This repository has been archived by the owner on Mar 11, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
80 lines (65 loc) · 1.81 KB
/
index.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
78
79
80
var winston = require('winston');
import levels from './levels/levels';
import colors from './levels/colors';
import formatter from './formatter';
winston.addColors(colors);
export function createConsoleTransport(options = {}) {
var transportOptions = {
level: 'trace',
colorize: true,
timestamp: function() {
var d = new Date();
var dayOfMonth = d.getDate();
if (dayOfMonth < 10) {
dayOfMonth = '0' + dayOfMonth;
}
return dayOfMonth + ' ' + d.toTimeString().split(' ')[0];
},
prettyPrint: true,
formatter: formatter
};
for (let k in options) {
transportOptions[k] = options;
}
return new winston.transports.Console(transportOptions);
}
var labelRewriter = function(msg, meta, level, logger) {
let label = logger && logger.label;
if (meta && meta.label) {
label = meta.label;
delete meta.label;
}
if (label) {
msg = '[' + label + '] ' + msg;
}
return { msg, meta };
};
export function createLogger(options = {}) {
if (!options.transports) {
options.transports = [
createConsoleTransport(options.consoleTransportOptions)
];
}
options.levels = levels;
var logger = new winston.Logger(options);
logger.addFilter(labelRewriter.bind(logger));
return logger;
}
Object.defineProperty(exports, 'logger', {
configurable: true,
get: function() {
let logger = createLogger();
Object.defineProperty(exports, 'logger', {
value: logger
});
return logger;
}
});
export function createPrefixedLogger(logger, prefix) {
if (prefix == null) {
prefix = logger;
logger = exports.logger;
}
// can't do.
return logger;
}