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

Added support to send Console error logs to Loggly

  • Loading branch information
psquickitjayant
psquickitjayant committed Dec 5, 2014
commit 6e3313b6b46f29576f4865f806302b9e5b922884
@@ -4,7 +4,7 @@
LOGGLY_INPUT_SUFFIX = '.gif?',
LOGGLY_SESSION_KEY = 'logglytrackingsession',
LOGGLY_SESSION_KEY_LENGTH = LOGGLY_SESSION_KEY.length + 1;

function uuid() {
// lifted from here -> http://stackoverflow.com/questions/105034/how-to-create-a-guid-uuid-in-javascript/2117523#2117523
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
@@ -15,18 +15,38 @@

function LogglyTracker() {
this.key = false;
this.sendConsoleErrors = true;
this.sendConsoleErrors = false;
}

function setKey(tracker, key) {
tracker.key = key;
tracker.setSession();
setInputUrl(tracker);
}

function setSendConsoleError(tracker, sendConsoleErrors) {
tracker.sendConsoleErrors = sendConsoleErrors;
}

function setSendConsoleError(tracker, sendConsoleErrors) {
tracker.sendConsoleErrors = sendConsoleErrors;

if(tracker.sendConsoleErrors === true){
var _onerror = window.onerror;
//send console error messages to Loggly
window.onerror = function (msg, url, line, col){
tracker.push({
category: 'BrowserJsException',
exception: {
message: msg,
url: url,
lineno: line,
colno: col,
}
});

if (_onerror && typeof _onerror === 'function') {
_onerror.apply(window, arguments);
}
};
}
}

function setInputUrl(tracker) {
tracker.inputUrl = LOGGLY_INPUT_PREFIX
@@ -68,21 +88,26 @@
self.logglyCollectorDomain = data.logglyCollectorDomain;
return;
}
if(data.sendConsoleErrors !== undefined) {
setSendConsoleError(self, data.sendConsoleErrors);

if(data.setConsoleError !== undefined) {
setSendConsoleError(self, data.setConsoleError);
}
if(data.logglyKey) {

if(data.logglyKey) {
setKey(self, data.logglyKey);
return;
}

if(data.session_id) {
self.setSession(data.session_id);
return;
}
}
if(!self.key) {

if(!self.key) {
return;
}

self.track(data);
}, 0);

@@ -133,23 +158,6 @@
}
}

//send console error messages to Loggly
window.onerror = function (msg, url, line, col){

if(tracker.sendConsoleErrors === true){
tracker.push({
category: 'BrowserJsException',
exception:
{
message: msg,
url: url,
lineno: line,
colno: col,
}
});
}
};

window._LTracker = tracker; // default global tracker

window.LogglyTracker = LogglyTracker; // if others want to instantiate more than one tracker
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.