Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support to send Console error logs to Loggly #6

Merged
merged 5 commits into from Dec 5, 2014
Merged
Changes from 1 commit
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

Fixed indentation

  • Loading branch information
psquickitjayant
psquickitjayant committed Dec 3, 2014
commit 221c3632ef5f38d31b92bada895c078551f56897
@@ -136,17 +136,17 @@
//send console error messages to Loggly
window.onerror = function (msg, url, line, col){

This comment has been minimized.

@vhalbwachs

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(tracker.sendConsoleErrors === true){
tracker.push({
category: 'BrowserJsException',
exception:
{
message: msg,
url: url,
lineno: line,
colno: col,
}
});
if(tracker.sendConsoleErrors === true){
tracker.push({
category: 'BrowserJsException',
exception:
{
message: msg,
url: url,
lineno: line,
colno: col,
}
});
}
};

ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.