loggly-jslogger
Advanced tools
Comparing version 2.2.2 to 2.2.4
@@ -21,2 +21,3 @@ (function (window, document) { | ||
this.useDomainProxy = false; | ||
this.useUtfEncoding = false; | ||
} | ||
@@ -40,2 +41,6 @@ | ||
function setUtfEncoding(tracker, useUtfEncoding){ | ||
tracker.useUtfEncoding = useUtfEncoding; | ||
} | ||
function setSendConsoleError(tracker, sendConsoleErrors) { | ||
@@ -129,2 +134,6 @@ tracker.sendConsoleErrors = sendConsoleErrors; | ||
if (data.useUtfEncoding !== undefined) { | ||
setUtfEncoding(self, data.useUtfEncoding); | ||
} | ||
if (data.useDomainProxy) { | ||
@@ -161,3 +170,7 @@ setDomainProxy(self, data.useDomainProxy); | ||
xmlHttp.open('POST', this.inputUrl, true); //true for asynchronous request | ||
xmlHttp.setRequestHeader('Content-Type', 'text/plain'); | ||
if (tracker.useUtfEncoding === true) { | ||
xmlHttp.setRequestHeader('Content-Type', 'text/plain; charset=utf-8'); | ||
} else { | ||
xmlHttp.setRequestHeader('Content-Type', 'text/plain'); | ||
} | ||
xmlHttp.send(JSON.stringify(data)); | ||
@@ -164,0 +177,0 @@ |
@@ -1,2 +0,2 @@ | ||
!function(o,s){function e(){return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(o){var s=16*Math.random()|0;return("x"==o?s:3&s|8).toString(16)})}function n(){this.key=!1,this.sendConsoleErrors=!1,this.tag="jslogger",this.useDomainProxy=!1}function t(o,s){o.key=s,o.setSession(),a(o)}function i(o,s){o.tag=s}function r(o,s){o.useDomainProxy=s,a(o)}function l(s,e){if(s.sendConsoleErrors=e,!0===s.sendConsoleErrors){var n=o.onerror;o.onerror=function(e,t,i,r,l){s.push({category:"BrowserJsException",exception:{message:e,url:t,lineno:i,colno:r,stack:l?l.stack:"n/a"}}),n&&"function"==typeof n&&n.apply(o,arguments)}}}function a(s){1==s.useDomainProxy?s.inputUrl=g+o.location.host+"/"+u+"/inputs/"+s.key+"/tag/"+s.tag:s.inputUrl=g+(s.logglyCollectorDomain||c)+"/inputs/"+s.key+"/tag/"+s.tag}var g="http"+("https:"===s.location.protocol?"s":"")+"://",c="logs-01.loggly.com",x="logglytrackingsession".length+1,u="loggly";n.prototype={setSession:function(o){o?(this.session_id=o,this.setCookie(this.session_id)):this.session_id||(this.session_id=this.readCookie(),this.session_id||(this.session_id=e(),this.setCookie(this.session_id)))},push:function(o){var s=typeof o;if(o&&("object"===s||"string"===s)){var e=this;if("string"===s)o={text:o};else{if(o.logglyCollectorDomain)return void(e.logglyCollectorDomain=o.logglyCollectorDomain);if(void 0!==o.sendConsoleErrors&&l(e,o.sendConsoleErrors),o.tag&&i(e,o.tag),o.useDomainProxy&&r(e,o.useDomainProxy),o.logglyKey)return void t(e,o.logglyKey);if(o.session_id)return void e.setSession(o.session_id)}e.key&&e.track(o)}},track:function(s){s.sessionId=this.session_id;try{var e=new XMLHttpRequest;e.open("POST",this.inputUrl,!0),e.setRequestHeader("Content-Type","text/plain"),e.send(JSON.stringify(s))}catch(e){o&&o.console&&"function"==typeof o.console.log&&(console.log("Failed to log to loggly because of this exception:\n"+e),console.log("Failed log data:",s))}},readCookie:function(){var o=s.cookie,e=o.indexOf("logglytrackingsession");if(e<0)return!1;var n=o.indexOf(";",e+1);return n=n<0?o.length:n,o.slice(e+x,n)},setCookie:function(o){s.cookie="logglytrackingsession="+o}};var y=o._LTracker,f=new n;if(y&&y.length){var d=0,h=y.length;for(d=0;d<h;d++)f.push(y[d])}o._LTracker=f,o.LogglyTracker=n}(window,document); | ||
//# sourceMappingURL=loggly.tracker-2.2.2.min.map | ||
!function(x,t){var e="http"+("https:"===t.location.protocol?"s":"")+"://",s="logs-01.loggly.com",n="logglytrackingsession",i=n.length+1,r="loggly";function o(){this.key=!1,this.sendConsoleErrors=!1,this.tag="jslogger",this.useDomainProxy=!1,this.useUtfEncoding=!1}function u(o){1==o.useDomainProxy?o.inputUrl=e+x.location.host+"/"+r+"/inputs/"+o.key+"/tag/"+o.tag:o.inputUrl=e+(o.logglyCollectorDomain||s)+"/inputs/"+o.key+"/tag/"+o.tag}o.prototype={setSession:function(o){o?(this.session_id=o,this.setCookie(this.session_id)):this.session_id||(this.session_id=this.readCookie(),this.session_id||(this.session_id="xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(o){var e=16*Math.random()|0;return("x"==o?e:3&e|8).toString(16)}),this.setCookie(this.session_id)))},push:function(o){var e=typeof o;if(o&&("object"===e||"string"===e)){var s,t,n,i,r,l,a,g,c=this;if("string"===e)o={text:o};else{if(o.logglyCollectorDomain)return void(c.logglyCollectorDomain=o.logglyCollectorDomain);if(void 0!==o.sendConsoleErrors&&function(i,o){if(i.sendConsoleErrors=o,!0===i.sendConsoleErrors){var r=x.onerror;x.onerror=function(o,e,s,t,n){i.push({category:"BrowserJsException",exception:{message:o,url:e,lineno:s,colno:t,stack:n?n.stack:"n/a"}}),r&&"function"==typeof r&&r.apply(x,arguments)}}}(c,o.sendConsoleErrors),o.tag&&(a=c,g=o.tag,a.tag=g),void 0!==o.useUtfEncoding&&(r=c,l=o.useUtfEncoding,r.useUtfEncoding=l),o.useDomainProxy&&(n=c,i=o.useDomainProxy,n.useDomainProxy=i,u(n)),o.logglyKey)return s=c,t=o.logglyKey,s.key=t,s.setSession(),void u(s);if(o.session_id)return void c.setSession(o.session_id)}c.key&&c.track(o)}},track:function(e){e.sessionId=this.session_id;try{var o=new XMLHttpRequest;o.open("POST",this.inputUrl,!0),!0===a.useUtfEncoding?o.setRequestHeader("Content-Type","text/plain; charset=utf-8"):o.setRequestHeader("Content-Type","text/plain"),o.send(JSON.stringify(e))}catch(o){x&&x.console&&"function"==typeof x.console.log&&(console.log("Failed to log to loggly because of this exception:\n"+o),console.log("Failed log data:",e))}},readCookie:function(){var o=t.cookie,e=o.indexOf(n);if(e<0)return!1;var s=o.indexOf(";",e+1);return s=s<0?o.length:s,o.slice(e+i,s)},setCookie:function(o){t.cookie=n+"="+o}};var l=x._LTracker,a=new o;if(l&&l.length){var g=0,c=l.length;for(g=0;g<c;g++)a.push(l[g])}x._LTracker=a,x.LogglyTracker=o}(window,document); | ||
//# sourceMappingURL=loggly.tracker-2.2.4.min.map |
@@ -21,2 +21,3 @@ (function (window, document) { | ||
this.useDomainProxy = false; | ||
this.useUtfEncoding = false; | ||
} | ||
@@ -40,2 +41,6 @@ | ||
function setUtfEncoding(tracker, useUtfEncoding){ | ||
tracker.useUtfEncoding = useUtfEncoding; | ||
} | ||
function setSendConsoleError(tracker, sendConsoleErrors) { | ||
@@ -129,2 +134,6 @@ tracker.sendConsoleErrors = sendConsoleErrors; | ||
if (data.useUtfEncoding !== undefined) { | ||
setUtfEncoding(self, data.useUtfEncoding); | ||
} | ||
if (data.useDomainProxy) { | ||
@@ -161,3 +170,7 @@ setDomainProxy(self, data.useDomainProxy); | ||
xmlHttp.open('POST', this.inputUrl, true); //true for asynchronous request | ||
xmlHttp.setRequestHeader('Content-Type', 'text/plain'); | ||
if (tracker.useUtfEncoding === true) { | ||
xmlHttp.setRequestHeader('Content-Type', 'text/plain; charset=utf-8'); | ||
} else { | ||
xmlHttp.setRequestHeader('Content-Type', 'text/plain'); | ||
} | ||
xmlHttp.send(JSON.stringify(data)); | ||
@@ -164,0 +177,0 @@ |
require('./src/loggly.tracker'); | ||
module.exports._LTracker = window._LTracker; | ||
module.exports.LogglyTracker = window.LogglyTracker; |
{ | ||
"name": "loggly-jslogger", | ||
"version": "2.2.2", | ||
"version": "2.2.4", | ||
"description": "A Javascript client to send logs to Loggly.", | ||
@@ -19,7 +19,10 @@ "browser": "index.js", | ||
"devDependencies": { | ||
"bower": "^1.8.0", | ||
"grunt": "^1.0.1", | ||
"bower": "^1.8.12", | ||
"grunt": "^1.3.0", | ||
"grunt-contrib-copy": "^1.0.0", | ||
"grunt-contrib-uglify": "^3.0.1" | ||
"grunt-contrib-uglify": "^3.4.0" | ||
}, | ||
"scripts": { | ||
"build": "grunt" | ||
} | ||
} |
@@ -1,24 +0,27 @@ | ||
loggly-jslogger | ||
=============== | ||
# 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 send Javascript logs from any website to Loggly. Check out Loggly’s [Javascript logging documentation](https://documentation.solarwinds.com/en/Success_Center/loggly/default.htm#cshid=loggly_javascript) to learn more. | ||
Installation | ||
------------ | ||
## Installation | ||
Place the following on your page, and replace the logglyKey value with the key provided by the website: | ||
Insert the following code into your webpage, replacing `your-customer-token` with the key defined in the `Source Setup -> Customer Tokens` page: | ||
```html | ||
<script type="text/javascript" src="/js/loggly.tracker.js" async></script> | ||
<script type="text/javascript" src="https://cloudfront.loggly.com/js/loggly.tracker-2.2.4.min.js" async></script> | ||
<script> | ||
var _LTracker = _LTracker || []; | ||
_LTracker.push({ | ||
'logglyKey': 'your-customer-token', | ||
'sendConsoleErrors' : true, | ||
'tag' : 'javascript-logs' | ||
}); | ||
'logglyKey': 'your-customer-token', | ||
'sendConsoleErrors': true, | ||
'tag': 'javascript-logs' | ||
}); | ||
</script> | ||
``` | ||
Usage | ||
----- | ||
To get early access to the most recent updates to the tracker, use the script [https://cloudfront.loggly.com/js/loggly.tracker-latest.min.js](https://cloudfront.loggly.com/js/loggly.tracker-latest.min.js). This is not recommended in a production environment as it may include breaking changes. | ||
## Usage | ||
Logging text: | ||
```javascript | ||
@@ -29,2 +32,3 @@ _LTracker.push('my tracking string'); | ||
Logging JSON: | ||
```javascript | ||
@@ -41,6 +45,6 @@ _LTracker.push({ | ||
Customization | ||
------------- | ||
## Customization | ||
separate logging instace: | ||
Separate logging instance: | ||
```javascript | ||
@@ -51,9 +55,8 @@ var myBetterLogger = new LogglyTracker(); | ||
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. | ||
## Send Console Errors to Loggly | ||
Send Tags to Loggly | ||
---- | ||
Keep the **sendConsoleErrors** value to *true* to send all unhandled errors to Loggly with detailed information, including error message, URL, line number and column number. | ||
## Send Tags to Loggly | ||
Send your custom tags to Loggly by setting the `tag` property. | ||
@@ -69,6 +72,22 @@ | ||
Setup Proxy for Ad blockers | ||
---------- | ||
You can proxy the requests from your own domain if the script or its requests are blocked by Ad blockers. To do this, you need to perform following steps | ||
## Special Characters Support | ||
Set the **useUtfEncoding** value to *true* to prevent special characters from showing as odd or unusual characters in Loggly Search. Special characters will be easier to read and understand in your log events. | ||
See the usage below: | ||
```Javascript | ||
_LTracker.push({ | ||
'logglyKey': 'your-customer-token', | ||
'sendConsoleErrors' : true, | ||
'tag' : 'javascript-logs', | ||
'useUtfEncoding': true | ||
}); | ||
``` | ||
## Setup Proxy for Ad blockers | ||
If the script or its requests are blocked by ad blockers, you can proxy requests from your own domain. To do this, perform following steps | ||
Set `useProxyDomain` property to true | ||
@@ -87,19 +106,19 @@ | ||
``` | ||
```text | ||
#Proxy to Loggly | ||
location /loggly/ { | ||
rewrite ^/loggly/(.*)$ /$1 break; # remove the '/loggly' part from the path, leaving /inputs/xxxxxxxx-xxxx-.../tag/xxx | ||
proxy_set_header Host logs-01.loggly.com; | ||
proxy_set_header X-Real-IP $remote_addr; | ||
proxy_set_header X-Forwarded-For $remote_addr; | ||
proxy_pass http://logs-01.loggly.com; | ||
proxy_set_header Host logs-01.loggly.com; | ||
proxy_set_header X-Real-IP $remote_addr; | ||
proxy_set_header X-Forwarded-For $remote_addr; | ||
proxy_pass http://logs-01.loggly.com; | ||
} | ||
``` | ||
Build min and map file | ||
---------- | ||
You can build min and map file by using the command below: | ||
``` | ||
npm install | ||
grunt | ||
``` | ||
## Build Production Version | ||
Run `npm run build` to build production version. The output is saved in folder `dist`. | ||
## Run tests | ||
In your web browser open file `jasminetest/TrackerSpecRunner.html`. |
@@ -21,2 +21,3 @@ (function (window, document) { | ||
this.useDomainProxy = false; | ||
this.useUtfEncoding = false; | ||
} | ||
@@ -40,2 +41,6 @@ | ||
function setUtfEncoding(tracker, useUtfEncoding){ | ||
tracker.useUtfEncoding = useUtfEncoding; | ||
} | ||
function setSendConsoleError(tracker, sendConsoleErrors) { | ||
@@ -129,2 +134,6 @@ tracker.sendConsoleErrors = sendConsoleErrors; | ||
if (data.useUtfEncoding !== undefined) { | ||
setUtfEncoding(self, data.useUtfEncoding); | ||
} | ||
if (data.useDomainProxy) { | ||
@@ -161,3 +170,7 @@ setDomainProxy(self, data.useDomainProxy); | ||
xmlHttp.open('POST', this.inputUrl, true); //true for asynchronous request | ||
xmlHttp.setRequestHeader('Content-Type', 'text/plain'); | ||
if (tracker.useUtfEncoding === true) { | ||
xmlHttp.setRequestHeader('Content-Type', 'text/plain; charset=utf-8'); | ||
} else { | ||
xmlHttp.setRequestHeader('Content-Type', 'text/plain'); | ||
} | ||
xmlHttp.send(JSON.stringify(data)); | ||
@@ -164,0 +177,0 @@ |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
43614
751
120
0