(function(n,t){typeof define=="function"&&define.amd?define(function(){return t(n)}):typeof exports=="object"?(typeof global=="object"&&(n=global),module.exports=t(n)):n.LE=t(n)})(this,function(n){"use strict";function f(t){var c=t.trace?(Math.random()+Math.PI).toString(36).substring(2,10):null,l=t.page_info,a=t.token,p=t.print,w=t.no_format,b=function(){return typeof XDomainRequest=="undefined"?t.ssl:n.location.protocol==="https:"?!0:!1}(),f,s,y,o;f=n.LEENDPOINT?n.LEENDPOINT:w?"webhook.logentries.com/noformat":"js.logentries.com/v1";f=(b?"https://":"http://")+f+"/logs/"+a;var k=!0,i=[],e=!1,v=!1;t.catchall&&(s=n.onerror,y=function(n,t,i){return h({error:n,line:i,location:t}).level("ERROR").send(),s?s(n,t,i):!1},n.onerror=y);var d=function(){var t=n.navigator||{doNotTrack:undefined},i=n.screen||{},r=n.location||{};return{url:r.pathname,referrer:document.referrer,screen:{width:i.width,height:i.height},window:{width:n.innerWidth,height:n.innerHeight},browser:{name:t.appName,version:t.appVersion,cookie_enabled:t.cookieEnabled,do_not_track:t.doNotTrack},platform:t.platform}},g=function(){var t=null,n=Array.prototype.slice.call(arguments);if(n.length===0)throw new Error("No arguments!");else t=n.length===1?n[0]:n;return t},h=function(){var t=g.apply(this,arguments),n={event:t};return l!=="never"&&(v&&l!=="per-entry"||(v=!0,typeof t.screen=="undefined"&&typeof t.browser=="undefined"&&h(d()).level("PAGE").send())),c&&(n.trace=c),{level:function(t){if(p&&typeof console!="undefined"&&t!=="PAGE"){var u=null;typeof XDomainRequest!="undefined"&&(u=n.trace+" "+n.event);try{console[t.toLowerCase()].call(console,u||n)}catch(f){console.log(u||n)}}return n.level=t,{send:function(){var t=[],u=JSON.stringify(n,function(n,i){if(typeof i=="undefined")return"undefined";if(typeof i=="object"&&i!==null){if(r(t,i)!==-1)return"<?>";t.push(i)}return i});e?i.push(u):o(a,u)}}}}};this.log=h;o=function(n,t){e=!0;var r=u();k&&(r.constructor===XMLHttpRequest?r.onreadystatechange=function(){r.readyState===4&&(r.status>=400?(console.error("Couldn't submit events."),r.status===410&&console.warn("This version of le_js is no longer supported!")):(r.status===301&&console.warn("This version of le_js is deprecated! Consider upgrading."),i.length>0?o(n,i.shift()):e=!1))}:r.onload=function(){i.length>0?o(n,i.shift()):e=!1},r.open("POST",f,!0),r.constructor===XMLHttpRequest&&(r.setRequestHeader("X-Requested-With","XMLHttpRequest"),r.setRequestHeader("Content-type","application/json")),r.overrideMimeType&&r.overrideMimeType("text"),r.send(t))}}function e(n){var i,r={ssl:!0,catchall:!1,trace:!0,page_info:"never",print:!1,endpoint:null,token:null},u,t;if(typeof n=="object")for(u in n)r[u]=n[u];else throw new Error("Invalid parameters for createLogStream()");if(r.token===null)throw new Error("Token not present.");else i=new f(r);return t=function(){if(i)return i.log.apply(this,arguments);throw new Error("You must call LE.init(...) first.");},{log:function(){t.apply(this,arguments).level("LOG").send()},warn:function(){t.apply(this,arguments).level("WARN").send()},error:function(){t.apply(this,arguments).level("ERROR").send()},info:function(){t.apply(this,arguments).level("INFO").send()}}}var r=function(n,t){for(var i=0;i<n.length;i++)if(t===n[i])return i;return-1},u=function(){return typeof XDomainRequest!="undefined"?new XDomainRequest:new XMLHttpRequest},t={},o=function(n){if(!t.hasOwnProperty(n))throw new Error("Invalid name for logStream");return t[n]},i=function(n){if(typeof n.name!="string")throw new Error("Name not present.");else if(t.hasOwnProperty(n.name))throw new Error("A logger with that name already exists!");return t[n.name]=new e(n),!0},s=function(n){var t={name:"default"},r;if(typeof n=="object")for(r in n)t[r]=n[r];else if(typeof n=="string")t.token=n;else throw new Error("Invalid parameters for init()");return i(t)},h=function(n){typeof n=="undefined"&&(n="default");delete t[n]};return{init:s,createLogStream:i,to:o,destroy:h,log:function(){for(var n in t)t[n].log.apply(this,arguments)},warn:function(){for(var n in t)t[n].warn.apply(this,arguments)},error:function(){for(var n in t)t[n].error.apply(this,arguments)},info:function(){for(var n in t)t[n].info.apply(this,arguments)}}});var loggingService=function(){return{init:function(n){LE.init({token:n})},log:function(n){LE.log(n)},logWarn:function(n){LE.warn(n)},logError:function(n){LE.error(n)},logInfo:function(n){LE.info(n)}}}()