Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upGitHub is where the world builds software
Millions of developers and companies build, ship, and maintain their software on GitHub — the largest and most advanced development platform in the world.
Added support to send Console error logs to Loggly #6
Conversation
|
We use 4 spaces for indentation, do you mind converting your tabs to spaces to keep things consistent? |
| @@ -129,6 +133,23 @@ | |||
| } | |||
| } | |||
|
|
|||
| //send console error messages to Loggly | |||
| window.onerror = function (msg, url, line, col){ | |||
vhalbwachs
Dec 3, 2014
Contributor
If someone assigns an event handler to window.onerror before our script loads, this will overwrite it.
To be safe, we should probably do the following:
*Wait until a user explicitly sets setConsoleError = true before overriding window.onerror (so basically move window.onerror assignment into setSendConsoleErrors). If setConsoleError is never specified, it's defaulted to false.
*Update readme to explain new proprty (I can help with that if you want)
<script type="text/javascript" src="/js/loggly.tracker.js" async></script>
<script>
var _LTracker = _LTracker || [];
_LTracker.push({
'logglyKey': '8c518f97-e3e0-4bfb-a8ed-582d084a5289',
'setConsoleError': true
});
</script>
*Also, just to be safe, we could also save a reference to window.onerror before overwriting it, then calling that as well so we reduce the risk of breaking functionality on a clients page in case they don't realize some library depends on window.onerror as well. So for example, you could do something like this:
var _onerror = window.onerror;
window.onerror = function(msg, url, line, col) {
if (tracker.sendConsoleErrors) {
tracker.push({
category: 'BrowserJsException',
exception: {
message: msg,
url: url,
lineno: line,
colno: col,
}
});
}
if (_onerror && typeof _onerror === 'function') {
_onerror.apply(window, arguments);
}
};
If someone assigns an event handler to window.onerror before our script loads, this will overwrite it.
To be safe, we should probably do the following:
*Wait until a user explicitly sets setConsoleError = true before overriding window.onerror (so basically move window.onerror assignment into setSendConsoleErrors). If setConsoleError is never specified, it's defaulted to false.
*Update readme to explain new proprty (I can help with that if you want)
<script type="text/javascript" src="/js/loggly.tracker.js" async></script>
<script>
var _LTracker = _LTracker || [];
_LTracker.push({
'logglyKey': '8c518f97-e3e0-4bfb-a8ed-582d084a5289',
'setConsoleError': true
});
</script> *Also, just to be safe, we could also save a reference to window.onerror before overwriting it, then calling that as well so we reduce the risk of breaking functionality on a clients page in case they don't realize some library depends on window.onerror as well. So for example, you could do something like this:
var _onerror = window.onerror;
window.onerror = function(msg, url, line, col) {
if (tracker.sendConsoleErrors) {
tracker.push({
category: 'BrowserJsException',
exception: {
message: msg,
url: url,
lineno: line,
colno: col,
}
});
}
if (_onerror && typeof _onerror === 'function') {
_onerror.apply(window, arguments);
}
};|
Nice Work |
Added support to send Console error logs to Loggly
Added support for amazon ami
Added a configurable field to the library to send console errors to Loggly. Default value is true.