-
Notifications
You must be signed in to change notification settings - Fork 49
/
angular-loggly-logger.min.js
2 lines (2 loc) · 3.59 KB
/
angular-loggly-logger.min.js
1
2
!function(a){"use strict";a.module("logglyLogger.logger",[]).provider("LogglyLogger",function(){var b=this,c=["DEBUG","INFO","WARN","ERROR"],d=!0,e={},f=!1,g=!1,h=!1,i=null,j=!1,k=!0,l=!0,m={},n=!1,o=0,p=null,q=function(){return(d?"https":"http")+"://logs-01.loggly.com/inputs/"+p+"/tag/"+(i||"AngularJS")+"/"};this.setExtra=function(a){return e=a,b},this.fields=function(c){return a.isDefined(c)?(a.extend(e,c),b):e},this.labels=function(c){return a.isObject(c)?(m=c,b):m},this.inputToken=function(c){return a.isDefined(c)?(p=c,b):p},this.useHttps=function(c){return a.isDefined(c)?(d=!!c,b):d},this.includeUrl=function(c){return a.isDefined(c)?(f=!!c,b):f},this.includeTimestamp=function(c){return a.isDefined(c)?(g=!!c,b):g},this.includeUserAgent=function(c){return a.isDefined(c)?(h=!!c,b):h},this.inputTag=function(c){return a.isDefined(c)?(i=c,b):i},this.sendConsoleErrors=function(c){return a.isDefined(c)?(j=!!c,b):j},this.level=function(d){if(a.isDefined(d)){var e=c.indexOf(d.toUpperCase());if(e<0)throw"Invalid logging level specified: "+d;return o=e,b}return c[o]},this.isLevelEnabled=function(a){return c.indexOf(a.toUpperCase())>=o},this.loggingEnabled=function(c){return a.isDefined(c)?(l=!!c,b):l},this.logToConsole=function(c){return a.isDefined(c)?(k=!!c,b):k},this.deleteHeaders=function(c){return a.isDefined(c)?(n=!!c,b):n},this.$get=["$injector",function(c){var d=null,i=function(b){if(p&&l){var i=c.get("$window"),j=c.get("$location"),k=c.get("$http");d=new Date;var o=a.extend({},e,b);f&&(o.url=j.absUrl()),g&&(o.timestamp=d.toISOString()),h&&(o.userAgent=i.navigator.userAgent);var r={headers:{"Content-Type":"text/plain"},withCredentials:!1};if(n){var s=Object.keys(k.defaults.headers.common).concat(Object.keys(k.defaults.headers.post));s=s.filter(function(a){return"Accept"!==a&&"Content-Type"!==a});for(var t=0;t<s.length;t++){var u=s[t];r.headers[u]=void 0}}for(var v in m)v in o&&(o[m[v]]=o[v],delete o[v]);k.post(q(),o,r).catch(console.error)}},r=function(){},s=function(b){return a.isDefined(b)&&(p=b),p};return{lastLog:function(){return d},sendConsoleErrors:function(){return j},level:function(){return o},loggingEnabled:b.loggingEnabled,isLevelEnabled:b.isLevelEnabled,inputTag:b.inputTag,attach:r,sendMessage:i,logToConsole:k,inputToken:s,fields:function(c){return a.isDefined(c)&&b.fields(c),b.fields()}}}]}),a.module("logglyLogger",["logglyLogger.logger"]).config(["$provide",function(b){b.decorator("$log",["$delegate","$injector",function(b,c){var d=c.get("LogglyLogger");if(!0===d.sendConsoleErrors()){var e=window.onerror;window.onerror=function(a,b,c,f,g){d.sendMessage({level:"ERROR",message:a,line:c,col:f,stack:g&&g.stack}),e&&"function"==typeof e&&e.apply(window,arguments)}}var f=function(b,c,e){var f=function(){var f=Array.prototype.slice.call(arguments);if(d.logToConsole&&b.apply(null,f),d.loggingEnabled()&&d.isLevelEnabled(c)){var g=(1===f.length?f[0]:f)||{},h={level:c};if(a.isDefined(g.stack)||a.isDefined(g[0])&&a.isDefined(g[0].stack)){if(!0!==d.sendConsoleErrors())return;h.message=g.message?g.message:g[0]&&g[0].message?g[0].message:null,h.stack=g.stack||g[0].stack}else a.isObject(g)?h=a.extend({},g,h):h.message=g;e&&(h.logger=g),d.sendMessage(h)}};return f.logs=[],f},g=function(a){return{log:a.log,info:a.info,warn:a.warn,error:a.error}}(b),h=function(a){return{log:f(g.log,"INFO",a),debug:f(g.debug,"DEBUG",a),info:f(g.info,"INFO",a),warn:f(g.warn,"WARN",a),error:f(g.error,"ERROR",a)}};return b.log=f(b.log,"INFO"),b.debug=f(b.debug,"DEBUG"),b.info=f(b.info,"INFO"),b.warn=f(b.warn,"WARN"),b.error=f(b.error,"ERROR"),b.getLogger=h,b}])}])}(window.angular);
//# sourceMappingURL=angular-loggly-logger.min.js.map