-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.js
More file actions
44 lines (41 loc) · 939 Bytes
/
index.js
File metadata and controls
44 lines (41 loc) · 939 Bytes
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
const winston = require('winston');
const validLogLevels = [
'emerg',
'alert',
'crit',
'error',
'warning',
'notice',
'info',
'debug',
];
const levels = validLogLevels.reduce((result, level, index) => {
result[level] = index;
return result;
}, {});
module.exports = {
createLogger: (logLevel='info', metadata={}, stderrLevels=[], { format } = {}) => {
return winston.createLogger({
format: format || winston.format.combine(
winston.format.timestamp({
format: 'YYYY-MM-DD HH:mm:ss'
}),
winston.format.errors({ stack: true }),
winston.format.splat(),
winston.format.simple()
),
defaultMeta: metadata,
level: logLevel,
levels,
transports: [
new winston.transports.Console({
handleExceptions: true,
stderrLevels,
})
]
});
},
format: winston.format,
levels,
validLogLevels
};