From 50d18d208b8bb2487f26c7796d303415ebc0b674 Mon Sep 17 00:00:00 2001 From: psquickitjayant Date: Wed, 26 Nov 2014 00:14:43 +0530 Subject: [PATCH 1/5] Added support to send Console error logs to Loggly --- src/loggly.tracker.js | 37 ++++++++++++++++++++++++++++++------- 1 file changed, 30 insertions(+), 7 deletions(-) diff --git a/src/loggly.tracker.js b/src/loggly.tracker.js index 217ef81..f94a316 100644 --- a/src/loggly.tracker.js +++ b/src/loggly.tracker.js @@ -4,7 +4,7 @@ LOGGLY_INPUT_SUFFIX = '.gif?', LOGGLY_SESSION_KEY = 'logglytrackingsession', LOGGLY_SESSION_KEY_LENGTH = LOGGLY_SESSION_KEY.length + 1; - + var sendConsoleErrors; 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) { @@ -22,6 +22,11 @@ tracker.setSession(); setInputUrl(tracker); } + + function setConsoleError(tracker,sendConsoleErrors) { + tracker.sendConsoleErrors = sendConsoleErrors; + } + function setInputUrl(tracker) { tracker.inputUrl = LOGGLY_INPUT_PREFIX @@ -63,22 +68,22 @@ self.logglyCollectorDomain = data.logglyCollectorDomain; return; } - - if(data.logglyKey) { + + if(data.sendConsoleErrors) { + setConsoleError(self, data.sendConsoleErrors); + } + 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); @@ -129,6 +134,24 @@ } } + //send console error messages to Loggly + window.onerror = function (msg, url, line, col){ + + if(_LTracker.sendConsoleErrors){ + _LTracker.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 From a829ac63671a520159d9cac7964cd8300463b80e Mon Sep 17 00:00:00 2001 From: psquickitjayant Date: Thu, 27 Nov 2014 00:14:10 +0530 Subject: [PATCH 2/5] Added support to send Console error logs to Loggly --- src/loggly.tracker.js | 52 +++++++++++++++++++++---------------------- 1 file changed, 25 insertions(+), 27 deletions(-) diff --git a/src/loggly.tracker.js b/src/loggly.tracker.js index f94a316..e68d511 100644 --- a/src/loggly.tracker.js +++ b/src/loggly.tracker.js @@ -4,7 +4,7 @@ LOGGLY_INPUT_SUFFIX = '.gif?', LOGGLY_SESSION_KEY = 'logglytrackingsession', LOGGLY_SESSION_KEY_LENGTH = LOGGLY_SESSION_KEY.length + 1; - var sendConsoleErrors; + 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,6 +15,7 @@ function LogglyTracker() { this.key = false; + this.sendConsoleErrors = true; } function setKey(tracker, key) { @@ -23,11 +24,10 @@ setInputUrl(tracker); } - function setConsoleError(tracker,sendConsoleErrors) { - tracker.sendConsoleErrors = sendConsoleErrors; - } + function setSendConsoleError(tracker, sendConsoleErrors) { + tracker.sendConsoleErrors = sendConsoleErrors; + } - function setInputUrl(tracker) { tracker.inputUrl = LOGGLY_INPUT_PREFIX + (tracker.logglyCollectorDomain || LOGGLY_COLLECTOR_DOMAIN) @@ -68,11 +68,10 @@ self.logglyCollectorDomain = data.logglyCollectorDomain; return; } - - if(data.sendConsoleErrors) { - setConsoleError(self, data.sendConsoleErrors); - } - if(data.logglyKey) { + if(data.sendConsoleErrors !== undefined) { + setSendConsoleError(self, data.sendConsoleErrors); + } + if(data.logglyKey) { setKey(self, data.logglyKey); return; } @@ -81,7 +80,7 @@ return; } } - if(!self.key) { + if(!self.key) { return; } self.track(data); @@ -134,23 +133,22 @@ } } - //send console error messages to Loggly - window.onerror = function (msg, url, line, col){ + //send console error messages to Loggly + window.onerror = function (msg, url, line, col){ - if(_LTracker.sendConsoleErrors){ - _LTracker.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, + } + }); + } + }; window._LTracker = tracker; // default global tracker From 221c3632ef5f38d31b92bada895c078551f56897 Mon Sep 17 00:00:00 2001 From: psquickitjayant Date: Wed, 3 Dec 2014 23:27:27 +0530 Subject: [PATCH 3/5] Fixed indentation --- src/loggly.tracker.js | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/src/loggly.tracker.js b/src/loggly.tracker.js index e68d511..b37e661 100644 --- a/src/loggly.tracker.js +++ b/src/loggly.tracker.js @@ -136,17 +136,17 @@ //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, - } - }); + if(tracker.sendConsoleErrors === true){ + tracker.push({ + category: 'BrowserJsException', + exception: + { + message: msg, + url: url, + lineno: line, + colno: col, + } + }); } }; From 6e3313b6b46f29576f4865f806302b9e5b922884 Mon Sep 17 00:00:00 2001 From: psquickitjayant Date: Fri, 5 Dec 2014 23:59:41 +0530 Subject: [PATCH 4/5] Added support to send Console error logs to Loggly --- src/loggly.tracker.js | 62 ++++++++++++++++++++++++------------------- 1 file changed, 35 insertions(+), 27 deletions(-) diff --git a/src/loggly.tracker.js b/src/loggly.tracker.js index b37e661..ad272c2 100644 --- a/src/loggly.tracker.js +++ b/src/loggly.tracker.js @@ -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,7 +15,7 @@ function LogglyTracker() { this.key = false; - this.sendConsoleErrors = true; + this.sendConsoleErrors = false; } function setKey(tracker, key) { @@ -23,10 +23,30 @@ 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 From 3e5944b5ddb4362bd6499c5d3e57ede6f56088e6 Mon Sep 17 00:00:00 2001 From: psquickitjayant Date: Sat, 6 Dec 2014 00:04:42 +0530 Subject: [PATCH 5/5] Update README.md --- README.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 99db567..a091447 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,10 @@ Place the following on your page, and replace the logglyKey value with the key p ```