-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathlogger.js
More file actions
39 lines (34 loc) · 956 Bytes
/
logger.js
File metadata and controls
39 lines (34 loc) · 956 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
const winston = require('winston');
const httpConext = require('express-http-context')
winston.remove(winston.transports.Console);
winston.add(new winston.transports.Console({
format: winston.format.combine(
winston.format.timestamp({
format: 'YYYY-MM-DD HH:mm:ss'
}),
winston.format.printf(info => `[${info.level} ${info.timestamp}] ${info.message}`)
)
}));
function addReqId(message) {
var id = httpConext.get('reqId');
if (typeof id == 'undefined') {
return message;
} else {
return `${id} - ${message}`;
}
}
var logger = {
log: function (level, message) {
winston.log(level, addReqId(message))
},
error: function(message) {
winston.error(addReqId(message))
},
warn: function(message) {
winston.warn(addReqId(message))
},
info: function(message) {
winston.info(addReqId(message))
},
}
module.exports = logger