|
11 | 11 | */
|
12 | 12 | 'use strict';
|
13 | 13 |
|
| 14 | +var wrapConsoleMethod = require('../src/console').wrapMethod; |
| 15 | + |
14 | 16 | function consolePlugin(Raven, console, pluginOptions) {
|
15 | 17 | console = console || window.console || {};
|
16 | 18 | pluginOptions = pluginOptions || {};
|
17 | 19 |
|
18 |
| - var originalConsole = console, |
19 |
| - logLevels = pluginOptions.levels || ['debug', 'info', 'warn', 'error'], |
| 20 | + var logLevels = pluginOptions.levels || ['debug', 'info', 'warn', 'error'], |
20 | 21 | level = logLevels.pop();
|
21 | 22 |
|
22 |
| - var logForGivenLevel = function(l) { |
23 |
| - var originalConsoleLevel = console[l]; |
24 |
| - |
25 |
| - // warning level is the only level that doesn't map up |
26 |
| - // correctly with what Sentry expects. |
27 |
| - if (l === 'warn') l = 'warning'; |
28 |
| - return function () { |
29 |
| - var args = [].slice.call(arguments); |
30 |
| - |
31 |
| - var msg = '' + args.join(' '); |
32 |
| - var data = {level: l, logger: 'console', extra: { 'arguments': args }}; |
33 |
| - if (pluginOptions.callback) { |
34 |
| - pluginOptions.callback(msg, data); |
35 |
| - } else { |
36 |
| - Raven.captureMessage(msg, data); |
37 |
| - } |
38 |
| - |
39 |
| - // this fails for some browsers. :( |
40 |
| - if (originalConsoleLevel) { |
41 |
| - // IE9 doesn't allow calling apply on console functions directly |
42 |
| - // See: https://stackoverflow.com/questions/5472938/does-ie9-support-console-log-and-is-it-a-real-function#answer-5473193 |
43 |
| - Function.prototype.apply.call( |
44 |
| - originalConsoleLevel, |
45 |
| - originalConsole, |
46 |
| - args |
47 |
| - ); |
48 |
| - } |
49 |
| - }; |
| 23 | + var callback = function (msg, data) { |
| 24 | + Raven.captureMessage(msg, data); |
50 | 25 | };
|
51 | 26 |
|
52 | 27 | while(level) {
|
53 |
| - console[level] = logForGivenLevel(level); |
| 28 | + wrapConsoleMethod(console, level, callback); |
54 | 29 | level = logLevels.pop();
|
55 | 30 | }
|
56 | 31 | }
|
|
0 commit comments