reorganize logger.js and use jquery
parent
e66b050c72
commit
3fd50bb01d
|
@ -16,6 +16,8 @@
|
||||||
// along with this program; if not, write to the Free Software
|
// along with this program; if not, write to the Free Software
|
||||||
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||||
//
|
//
|
||||||
|
$j.ajaxSetup({timeout: AJAX_TIMEOUT});
|
||||||
|
var reportLogs = true;
|
||||||
|
|
||||||
if ( !window.console ) {
|
if ( !window.console ) {
|
||||||
window.console =
|
window.console =
|
||||||
|
@ -28,55 +30,63 @@ if ( !window.console ) {
|
||||||
error: function() {}
|
error: function() {}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( !console.debug ) {
|
if ( !console.debug ) {
|
||||||
// IE8 has console but doesn't have console.debug so lets alias it.
|
// IE8 has console but doesn't have console.debug so lets alias it.
|
||||||
console.debug = console.log;
|
console.debug = console.log;
|
||||||
}
|
}
|
||||||
|
|
||||||
var reportLogs = true;
|
window.onerror = function(message, url, line) {
|
||||||
|
logReport("ERR", message, url, line);
|
||||||
|
};
|
||||||
|
|
||||||
var debugParms;
|
window.addEventListener("securitypolicyviolation", function logCSP(evt) {
|
||||||
var debugReq;
|
var level = evt.disposition == "enforce" ? "ERR" : "DBG";
|
||||||
|
var message = evt.blockedURI + " violated CSP " + evt.violatedDirective;
|
||||||
|
|
||||||
|
if ( evt.sample ) message += " (Sample: " + evt.sample + ")";
|
||||||
|
logReport(level, message, evt.sourceFile, evt.lineNumber);
|
||||||
|
});
|
||||||
|
|
||||||
function logReport( level, message, file, line ) {
|
function logReport( level, message, file, line ) {
|
||||||
if ( !reportLogs ) {
|
if ( !reportLogs ) return;
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( typeof(MooTools) == "undefined" ) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
/* eslint-disable no-caller */
|
/* eslint-disable no-caller */
|
||||||
if ( arguments && arguments.callee && arguments.callee.caller && arguments.callee.caller.caller && arguments.callee.caller.caller.name ) {
|
if ( arguments && arguments.callee && arguments.callee.caller && arguments.callee.caller.caller && arguments.callee.caller.caller.name ) {
|
||||||
message += ' - '+arguments.callee.caller.caller.name+'()';
|
message += ' - '+arguments.callee.caller.caller.name+'()';
|
||||||
//console.log("arguments");
|
//console.log("arguments");
|
||||||
} else {
|
|
||||||
//message += new Error().stack;
|
|
||||||
//console.log("stack");
|
|
||||||
}
|
}
|
||||||
/* eslint-enable no-caller */
|
|
||||||
|
|
||||||
if ( !debugReq ) {
|
var browser = {};
|
||||||
debugParms = "view=request&request=log&task=create";
|
|
||||||
if ( Browser ) {
|
if ( Browser ) {
|
||||||
debugParms += "&browser[name]="+Browser.name+"&browser[version]="+Browser.version+"&browser[platform]="+(Browser.Platform?Browser.Platform.name:'unknown');
|
browser.name = Browser.name;
|
||||||
|
browser.version = Browser.version;
|
||||||
|
browser.platform = Browser.Platform ? Browser.Platform.name : 'unknown';
|
||||||
} else {
|
} else {
|
||||||
debugParms += "&browser[name]=unknown&browser[version]=unknown&browser[platform]=unknown";
|
browser.name = 'unknown';
|
||||||
|
browser.version = 'unknown';
|
||||||
|
browser.platform = 'unknown';
|
||||||
}
|
}
|
||||||
debugReq = new Request.JSON({url: thisUrl, method: 'post', timeout: AJAX_TIMEOUT, link: 'chain'});
|
|
||||||
}
|
var data = {
|
||||||
var requestParms = debugParms;
|
view: 'request',
|
||||||
requestParms += "&level="+level+"&message="+encodeURIComponent(message);
|
request: 'log',
|
||||||
|
task: 'create',
|
||||||
|
level: level,
|
||||||
|
message: encodeURIComponent(message),
|
||||||
|
browser: browser
|
||||||
|
};
|
||||||
|
|
||||||
if ( file ) {
|
if ( file ) {
|
||||||
requestParms += "&file="+file;
|
data.file = file;
|
||||||
} else if ( location.search ) {
|
} else if ( location.search ) {
|
||||||
//location.search is the querystring part, so ?blah=blah but there is almost never any value to this
|
//location.search is the querystring part, so ?blah=blah but there is almost never any value to this
|
||||||
requestParms += "&file="+location.search;
|
data.file = location.search;
|
||||||
}
|
}
|
||||||
if ( line ) {
|
|
||||||
requestParms += "&line="+line;
|
if ( line ) data.line = line;
|
||||||
}
|
|
||||||
debugReq.send(requestParms);
|
$j.getJSON(thisUrl, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
function Panic(message) {
|
function Panic(message) {
|
||||||
|
@ -112,22 +122,6 @@ function Debug(message) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function Dump(value, label) {
|
function Dump(value, label) {
|
||||||
if ( label ) {
|
if ( label ) console.debug(label+" => ");
|
||||||
console.debug(label+" => ");
|
|
||||||
}
|
|
||||||
console.debug(value);
|
console.debug(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
window.onerror =
|
|
||||||
function( message, url, line ) {
|
|
||||||
logReport("ERR", message, url, line);
|
|
||||||
};
|
|
||||||
|
|
||||||
window.addEventListener("securitypolicyviolation", function logCSP(evt) {
|
|
||||||
var level = evt.disposition == "enforce" ? "ERR" : "DBG";
|
|
||||||
var message = evt.blockedURI + " violated CSP " + evt.violatedDirective;
|
|
||||||
if ( evt.sample ) {
|
|
||||||
message += " (Sample: " + evt.sample + ")";
|
|
||||||
}
|
|
||||||
logReport(level, message, evt.sourceFile, evt.lineNumber);
|
|
||||||
});
|
|
||||||
|
|
Loading…
Reference in New Issue