-
Notifications
You must be signed in to change notification settings - Fork 0
/
log.js
61 lines (47 loc) · 1.07 KB
/
log.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
var extend = function (target, src) {
//Only deals with objects. If terrible things happen..../shrug
//src overwrites keys in target
for (var key in src) {
if (!src.hasOwnProperty(key)) continue;
target[key] = src[key];
}
// Return the modified object
return target;
}
var Log = function ( options ) {
options = options || {};
options = extend({
logState : 'none',
logStates : [
'none',
'error',
'info',
'debug'
],
}, options);
console.dir();
// @private
// @string state
var levelIndex = function (state) {
return options.logStates.indexOf(state);
};
// @private, though this is what is returned...
// @string msg
// @object obj
// @string level
var log = function (msg, obj, level) {
level = level || 'debug';
//if the given level (by default, debug) is
//a higher level than the current logState,
//don't show it.
if ( levelIndex(level) > levelIndex(options.logState) ) {
return;
}
if (console) {
if (msg) console.log(msg);
if (obj) console.dir(obj);
}
return;
};
return log;
};