2
0
forked from Wavyzz/dolibarr

New Added client-side Sentry logging

Using Raven.js allows logging client-side javascript errors to the
configured Sentry server.
This commit is contained in:
Raphaël Doursenaud
2015-08-31 17:21:03 +02:00
parent 7ef5cbfb96
commit a6ef289470
47 changed files with 7872 additions and 9 deletions

View File

@@ -0,0 +1,43 @@
/**
* console plugin
*
* Monkey patches console.* calls into Sentry messages with
* their appropriate log levels. (Experimental)
*/
;(function(window, Raven, console) {
'use strict';
var originalConsole = console,
logLevels = ['debug', 'info', 'warn', 'error'],
level = logLevels.pop();
var logForGivenLevel = function(level) {
var originalConsoleLevel = console[level];
// warning level is the only level that doesn't map up
// correctly with what Sentry expects.
if (level === 'warn') level = 'warning';
return function () {
var args = [].slice.call(arguments);
Raven.captureMessage('' + args, {level: level, logger: 'console'});
// this fails for some browsers. :(
if (originalConsoleLevel) {
// IE9 doesn't allow calling apply on console functions directly
// See: https://stackoverflow.com/questions/5472938/does-ie9-support-console-log-and-is-it-a-real-function#answer-5473193
Function.prototype.bind
.call(originalConsoleLevel, originalConsole)
.apply(originalConsole, args);
}
};
};
while(level) {
console[level] = logForGivenLevel(level);
level = logLevels.pop();
}
// export
window.console = console;
}(window, window.Raven, window.console || {}));