-
Notifications
You must be signed in to change notification settings - Fork 0
/
logger.js
37 lines (33 loc) · 892 Bytes
/
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
const {
createLogger,
format: { combine, printf },
transports,
} = require('winston');
const loggerFormat = combine(
printf(({ level, meta = {} }) => {
const { message, details, req = {} } = meta;
const { headers = {}, path, hostname, user = {}, userAgent, accessPermissions } = req;
return JSON.stringify({
timestamp: Date.now(),
correlationId: headers['x-coreplatform-correlationid'],
log: {
level,
message,
details,
},
requestContext: {
tokenType: user.tokenType,
userId: user.userid,
host: hostname,
accessPermissions: accessPermissions,
userAgent,
path,
},
});
})
);
const logger = createLogger({
format: loggerFormat,
transports: [new transports.Console()],
});
module.exports = logger;