forked from ajbrown/angular-loggly-logger
-
Notifications
You must be signed in to change notification settings - Fork 0
/
angular-loggly-logger.min.js
2 lines (2 loc) · 2.98 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=null,i=!1,j=!0,k=!0,l=0,m=null,n="://logs-01.loggly.com/inputs/",o=function(){return(d?"https":"http")+n+m+"/tag/"+(h?h:"AngularJS")+"/"};this.setExtra=function(a){return e=a,b},this.fields=function(c){return a.isDefined(c)?(e=c,b):e},this.inputToken=function(c){return a.isDefined(c)?(m=c,b):m},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.inputTag=function(c){return a.isDefined(c)?(h=c,b):h},this.sendConsoleErrors=function(c){return a.isDefined(c)?(i=!!c,b):i},this.level=function(d){if(a.isDefined(d)){var e=c.indexOf(d.toUpperCase());if(0>e)throw"Invalid logging level specified: "+d;return l=e,b}return c[l]},this.isLevelEnabled=function(a){return c.indexOf(a.toUpperCase())>=l},this.loggingEnabled=function(c){return a.isDefined(c)?(k=!!c,b):k},this.logToConsole=function(c){return a.isDefined(c)?(j=!!c,b):j},this.$get=["$injector",function(c){var d=null,h=function(b){if(m&&k){var h=c.get("$location"),i=c.get("$http");d=new Date;var j=a.extend({},e,b);f&&(j.url=h.absUrl()),g&&(j.timestamp=d.toISOString());var l={headers:{"Content-Type":"text/plain"},withCredentials:!1};i.post(o(),j,l)}},n=function(){},p=function(b){return a.isDefined(b)&&(m=b),m};return{lastLog:function(){return d},sendConsoleErrors:function(){return i},level:function(){return l},loggingEnabled:b.loggingEnabled,isLevelEnabled:b.isLevelEnabled,attach:n,sendMessage:h,logToConsole:j,inputToken:p,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(d.sendConsoleErrors()===!0){var e=window.onerror;window.onerror=function(a,b,c,f){d.sendMessage({level:"ERROR",message:a,url:b,line:c,col:f}),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(d.sendConsoleErrors()!==!0)return;h.message=g.message||g[0].message,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.map