-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpretty-logger.js
77 lines (65 loc) · 2.93 KB
/
pretty-logger.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
(function () {
var pkginfo = require('pkginfo')(module, 'version'),
colors = require('colors'),
BasicLogger = require('basic-logger'),
_ = require('underscore'),
PrettyLogger;
exports.defaultConfig = {
error: "red",
info: "green",
warn: "yellow",
debug: "cyan",
trace: "grey"
};
module.exports = PrettyLogger = (function () {
function formatForConfig (msg, config) {
return Array.isArray(config)
? config.reduce(function (m, c) { return m[c]; }, msg)
: msg[config];
}
PrettyLogger.setLevel = BasicLogger.setLevel;
function PrettyLogger(config) {
if (config == null) config = {};
this.config = _.defaults(config, exports.defaultConfig);
var logger = new BasicLogger(config);
BasicLogger.prototype.error = function () {
var args, msg;
msg = arguments[0], args = 2 <= arguments.length ? _.toArray(arguments).slice(1) : [];
args.unshift(formatForConfig(msg, this.config.error), 'error');
return this.log.apply(this, args);
};
BasicLogger.prototype.info = function () {
var args, msg;
msg = arguments[0], args = 2 <= arguments.length ? _.toArray(arguments).slice(1) : [];
args.unshift(formatForConfig(msg, this.config.info), 'info');
return this.log.apply(this, args);
};
BasicLogger.prototype.warn = function () {
var args, msg;
msg = arguments[0], args = 2 <= arguments.length ? _.toArray(arguments).slice(1) : [];
args.unshift(formatForConfig(msg, this.config.warn), 'warning');
return this.log.apply(this, args);
};
BasicLogger.prototype.warning = function () {
var args, msg;
msg = arguments[0], args = 2 <= arguments.length ? _.toArray(arguments).slice(1) : [];
args.unshift(formatForConfig(msg, this.config.warn), 'warning');
return this.log.apply(this, args);
};
BasicLogger.prototype.debug = function () {
var args, msg;
msg = arguments[0], args = 2 <= arguments.length ? _.toArray(arguments).slice(1) : [];
args.unshift(formatForConfig(msg, this.config.debug), 'debug');
return this.log.apply(this, args);
};
BasicLogger.prototype.trace = function () {
var args, msg;
msg = arguments[0], args = 2 <= arguments.length ? _.toArray(arguments).slice(1) : [];
args.unshift(formatForConfig(msg, this.config.trace), 'trace');
return this.log.apply(this, args);
};
return logger;
}
return PrettyLogger;
})();
}).call(this);