-
Notifications
You must be signed in to change notification settings - Fork 0
/
logger.ts
36 lines (34 loc) · 925 Bytes
/
logger.ts
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
import { RequestMethod } from '@nestjs/common';
import { Params } from 'nestjs-pino';
export const pinoLoggerConfigFactory = (): Params => ({
pinoHttp: {
level: 'info',
messageKey: 'message',
timestamp: () => `,"timestamp":"${new Date(Date.now()).toISOString()}"`,
formatters: {
level: (label: string) => ({
level: label,
}),
log: (obj: any) => {
const { responseTime, ...info } = obj;
return {
...info,
duration: responseTime ? Number(responseTime) / 1000 : undefined,
};
},
},
customProps: function (req, res) {
return {
customProp: 'I will be duplicated',
};
},
base: {
environment: 'development',
service: 'pino-customprops-bug-api',
},
redact: {
paths: ['req.headers', 'res.headers'],
},
},
exclude: [{ method: RequestMethod.ALL, path: '/health' }],
});