-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
39 lines (34 loc) · 923 Bytes
/
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
const winston = require('winston').cli();
const uuid = require('uuid');
module.exports = (arg = 'console', filename = 'targetdummy.log') => {
const timestamp = Date.now();
// 'console' logger only outputs to the command line.
winston.loggers.add('console', {
console: {
json: true,
stringify: true,
timestamp,
},
});
// 'file' logger outputs to command line and persists to a flat file.
winston.loggers.add('file', {
console: {
json: true,
stringify: true,
timestamp,
},
file: {
json: true,
stringify: true,
timestamp,
filename,
},
});
// Get the winston logger that matches the argument flag.
const logger = winston.loggers.get(arg);
const request_id = uuid.v1();
return {
info: msg => logger.log('info', '%j', msg, { request_id }),
error: msg => logger.log('error', '%j', msg, { request_id }),
};
};