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

Add forceHTTPS in case of mobile where we are in file protocole #44

Open
wants to merge 11 commits into
base: master
from
@@ -0,0 +1 @@
node_modules/
@@ -7,7 +7,7 @@ module.exports = function (grunt) {
},
main : {
files : {
'src/loggly.tracker-2.1.min.js' : ['src/loggly.tracker.js']
'src/loggly.tracker-2.2.min.js' : ['src/loggly.tracker.js']
}
}
}
@@ -1,7 +1,7 @@
loggly-jslogger
===============

Client-side (browser) logger to use with Loggly gen2. Check out Loggly's [Javascript logging documentation](https://www.loggly.com/docs/javascript/) to learn more.
Client-side (browser) logger to use with Loggly gen2. Check out Loggly's [Javascript logging documentation](https://www.loggly.com/docs/javascript/) to learn more.

Installation
------------
@@ -48,7 +48,7 @@ myBetterLogger.push({'logglyKey': 'your-customer-token' }); // push a loggly ke

Send Console Errors to Loggly
----
Keeping <strong>sendConsoleErrors</strong> value to <i>true</i> will send all the unhandled errors to the Loggly with the detailed information like error message, URL, line number and column number. This script also take cares of all the previously defined window.onerror functions.
Keeping <strong>sendConsoleErrors</strong> value to <i>true</i> will send all the unhandled errors to the Loggly with the detailed information like error message, URL, line number and column number. This script also take cares of all the previously defined window.onerror functions.

Send Tags to Loggly
----
@@ -90,3 +90,17 @@ location /loggly/ {
proxy_pass http://logs-01.loggly.com;
}
```

Force HTTPS
----

If you don't want Loggly to detect what protocol to use and enforce https

```Javascript
_LTracker.push({
'logglyKey': 'your-customer-token',
'sendConsoleErrors' : true,
'tag' : 'javascript-logs',
'forceHTTPS':false
});
```
@@ -5,9 +5,9 @@
"_target": "*",
"_originalSource": "loggly-jslogger",
"_direct": true,
"version": "3.0.0",
"version": "3.1.0",
"description": "A Javascript client to send logs to Loggly.",
"main": "src/loggly.tracker.js",
"main": "src/loggly.tracker-2.2.min.js",
"keywords": [
"loggly-jslogger",
"jslogger",
@@ -1,6 +1,6 @@
{
"name": "loggly-jslogger",
"version": "2.1.0",
"version": "2.2.1",
"description": "A Javascript client to send logs to Loggly.",
"browser": "index.js",
"repository": {
@@ -12,7 +12,7 @@
"loggly-jslogger",
"jslogger",
"loggly",
"log"
"log"
],
"license": "MIT",
"devDependencies": {

Some generated files are not rendered by default. Learn more.

Some generated files are not rendered by default. Learn more.

@@ -1,49 +1,53 @@
(function(window, document) {
var LOGGLY_INPUT_PREFIX = 'http' + ( ('https:' === document.location.protocol ? 's' : '') ) + '://',
LOGGLY_COLLECTOR_DOMAIN = 'logs-01.loggly.com',
var LOGGLY_COLLECTOR_DOMAIN = 'logs-01.loggly.com',
LOGGLY_SESSION_KEY = 'logglytrackingsession',
LOGGLY_SESSION_KEY_LENGTH = LOGGLY_SESSION_KEY.length + 1,
LOGGLY_PROXY_DOMAIN = 'loggly';

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) {
var r = Math.random()*16|0, v = c == 'x' ? r : (r&0x3|0x8);
return v.toString(16);
});
});
}

function LogglyTracker() {
this.key = false;
this.sendConsoleErrors = false;
this.sendConsoleErrors = false;
this.tag = 'jslogger';
this.useDomainProxy = false;
this.forceHTTPS = false;
}

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

function setTag(tracker, tag){
tracker.tag = tag;
}


function setTag(tracker, tag){
tracker.tag = tag;
}

function setForceHTTPS(tracker, forceHTTPS){
tracker.forceHTTPS = forceHTTPS;
}

function setDomainProxy(tracker, useDomainProxy){
tracker.useDomainProxy = useDomainProxy;
//refresh inputUrl value
setInputUrl(tracker);
}

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({
tracker.push({
category: 'BrowserJsException',
exception: {
message: msg,
@@ -52,36 +56,40 @@
colno: col,
}
});

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

function setInputUrl(tracker) {

if(tracker.useDomainProxy == true){
tracker.inputUrl = LOGGLY_INPUT_PREFIX
tracker.inputUrl = getInputPrefix(tracker)
+ window.location.host
+ '/'
+ LOGGLY_PROXY_DOMAIN
+ '/inputs/'
+ tracker.key
+ tracker.key
+ '/tag/'
+ tracker.tag;
}
else{
tracker.inputUrl = LOGGLY_INPUT_PREFIX
tracker.inputUrl = getInputPrefix(tracker)
+ (tracker.logglyCollectorDomain || LOGGLY_COLLECTOR_DOMAIN)
+ '/inputs/'
+ tracker.key
+ tracker.key
+ '/tag/'
+ tracker.tag;
}
}


function getInputPrefix(tracker){
return 'http' + ('https:' === document.location.protocol || tracker.forceHTTPS ? 's' : '') + '://';
}

LogglyTracker.prototype = {
setSession: function(session_id) {
if(session_id) {
@@ -97,14 +105,14 @@
},
push: function(data) {
var type = typeof data;

if( !data || !(type === 'object' || type === 'string') ) {
return;
}

var self = this;


if(type === 'string') {
data = {
'text': data
@@ -114,49 +122,53 @@
self.logglyCollectorDomain = data.logglyCollectorDomain;
return;
}
if(data.sendConsoleErrors !== undefined) {
setSendConsoleError(self, data.sendConsoleErrors);

if(data.sendConsoleErrors !== undefined) {
setSendConsoleError(self, data.sendConsoleErrors);
}
if(data.tag) {

if(data.tag) {
setTag(self, data.tag);
}

if(data.useDomainProxy){

if(data.forceHTTPS) {
setForceHTTPS(self, data.forceHTTPS);
}

if(data.useDomainProxy){
setDomainProxy(self, data.useDomainProxy);
}

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

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

if(!self.key) {
return;
}

self.track(data);


},
track: function(data) {
// inject session id
data.sessionId = this.session_id;

try {
//creating an asynchronous XMLHttpRequest
var xmlHttp = new XMLHttpRequest();
xmlHttp.open('POST', this.inputUrl, true); //true for asynchronous request
xmlHttp.setRequestHeader('Content-Type', 'text/plain');
xmlHttp.send(JSON.stringify(data));
xmlHttp.open('POST', this.inputUrl, true); //true for asynchronous request
xmlHttp.setRequestHeader('Content-Type', 'text/plain');
xmlHttp.send(JSON.stringify(data));

} catch (ex) {
if (window && window.console && typeof window.console.log === 'function') {
console.log("Failed to log to loggly because of this exception:\n" + ex);
@@ -182,21 +194,21 @@
document.cookie = LOGGLY_SESSION_KEY + '=' + value;
}
};

var existing = window._LTracker;

var tracker = new LogglyTracker();

if(existing && existing.length ) {
var i = 0,
eLength = existing.length;
for(i = 0; i < eLength; i++) {
tracker.push(existing[i]);
}
}

window._LTracker = tracker; // default global tracker

window.LogglyTracker = LogglyTracker; // if others want to instantiate more than one tracker

})(window, document);
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.