commonroutesApp/www/lib/angular-simple-logger/dist/angular-simple-logger.light.js
www/lib/angular-simple-logger/dist/angular-simple-logger.light.jsRaw
1/**
2 * angular-simple-logger
3 *
4 * @version: 0.1.7
5 * @author: Nicholas McCready
6 * @date: Tue Jan 26 2016 10:15:01 GMT-0500 (EST)
7 * @license: MIT
8 */
9
10(function (window, angular){
11 angular.module('nemLogging', []);
12
13angular.module('nemLogging').provider('nemDebug', function (){
14 var ourDebug = null;
15
16 this.$get = function(){
17 //avail as service
18 return ourDebug;
19 };
20
21 //avail at provider, config time
22 this.debug = ourDebug;
23
24 return this;
25});
26var bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; },
27 slice = [].slice;
28
29angular.module('nemLogging').provider('nemSimpleLogger', [
30 'nemDebugProvider', function(nemDebugProvider) {
31 var LEVELS, Logger, _debugCache, _fns, _isValidLogObject, _maybeExecLevel, _wrapDebug, i, key, len, nemDebug, val;
32 nemDebug = nemDebugProvider.debug;
33 _debugCache = {};
34 _fns = ['debug', 'info', 'warn', 'error', 'log'];
35 LEVELS = {};
36 for (key = i = 0, len = _fns.length; i < len; key = ++i) {
37 val = _fns[key];
38 LEVELS[val] = key;
39 }
40 _maybeExecLevel = function(level, current, fn) {
41 if (level >= current) {
42 return fn();
43 }
44 };
45 _isValidLogObject = function(logObject) {
46 var isValid, j, len1;
47 isValid = false;
48 if (!logObject) {
49 return isValid;
50 }
51 for (j = 0, len1 = _fns.length; j < len1; j++) {
52 val = _fns[j];
53 isValid = (logObject[val] != null) && typeof logObject[val] === 'function';
54 if (!isValid) {
55 break;
56 }
57 }
58 return isValid;
59 };
60
61 /*
62 Overide logeObject.debug with a nemDebug instance
63 see: https://github.com/visionmedia/debug/blob/master/Readme.md
64 */
65 _wrapDebug = function(namespace, logObject) {
66 var debugInstance, j, len1, newLogger;
67 if (_debugCache[namespace] == null) {
68 _debugCache[namespace] = nemDebug(namespace);
69 }
70 debugInstance = _debugCache[namespace];
71 newLogger = {};
72 for (j = 0, len1 = _fns.length; j < len1; j++) {
73 val = _fns[j];
74 newLogger[val] = val === 'debug' ? debugInstance : logObject[val];
75 }
76 return newLogger;
77 };
78 Logger = (function() {
79 function Logger($log1) {
80 var fn1, j, len1, level, logFns;
81 this.$log = $log1;
82 this.spawn = bind(this.spawn, this);
83 if (!this.$log) {
84 throw 'internalLogger undefined';
85 }
86 if (!_isValidLogObject(this.$log)) {
87 throw '@$log is invalid';
88 }
89 this.doLog = true;
90 logFns = {};
91 fn1 = (function(_this) {
92 return function(level) {
93 logFns[level] = function() {
94 var args;
95 args = 1 <= arguments.length ? slice.call(arguments, 0) : [];
96 if (_this.doLog) {
97 return _maybeExecLevel(LEVELS[level], _this.currentLevel, function() {
98 var ref;
99 return (ref = _this.$log)[level].apply(ref, args);
100 });
101 }
102 };
103 return _this[level] = logFns[level];
104 };
105 })(this);
106 for (j = 0, len1 = _fns.length; j < len1; j++) {
107 level = _fns[j];
108 fn1(level);
109 }
110 this.LEVELS = LEVELS;
111 this.currentLevel = LEVELS.error;
112 }
113
114 Logger.prototype.spawn = function(newInternalLogger) {
115 if (typeof newInternalLogger === 'string') {
116 if (!_isValidLogObject(this.$log)) {
117 throw '@$log is invalid';
118 }
119 if (!nemDebug) {
120 throw 'nemDebug is undefined this is probably the light version of this library sep debug logggers is not supported!';
121 }
122 return _wrapDebug(newInternalLogger, this.$log);
123 }
124 return new Logger(newInternalLogger || this.$log);
125 };
126
127 return Logger;
128
129 })();
130 this.decorator = [
131 '$log', function($delegate) {
132 var log;
133 log = new Logger($delegate);
134 log.currentLevel = LEVELS.debug;
135 return log;
136 }
137 ];
138 this.$get = [
139 '$log', function($log) {
140 return new Logger($log);
141 }
142 ];
143 return this;
144 }
145]);
146
147})(window, angular);