-
Notifications
You must be signed in to change notification settings - Fork 230
/
logger.config.ts
42 lines (40 loc) · 1.3 KB
/
logger.config.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
37
38
39
40
41
42
import type { Request } from 'express';
import { nanoid } from 'nanoid';
import type { Params } from 'nestjs-pino';
import { multistream } from 'pino';
import type { ReqId } from 'pino-http';
const passUrl = new Set(['/health', '/graphql']);
export const loggerOptions: Params = {
pinoHttp: [
{
// https://getpino.io/#/docs/api?id=timestamp-boolean-function
// Change time value in production log.
// timestamp: stdTimeFunctions.isoTime,
quietReqLogger: true,
genReqId: (req): ReqId => (<Request>req).header('X-Request-Id') ?? nanoid(),
...(process.env.NODE_ENV === 'production'
? {}
: {
level: 'debug',
// https://github.com/pinojs/pino-pretty
transport: {
target: 'pino-pretty',
options: { sync: true, singleLine: true },
},
}),
autoLogging: {
ignore: (req) => passUrl.has((<Request>req).originalUrl),
},
customProps: (req) => (<Request>req).customProps,
},
multistream(
[
// https://getpino.io/#/docs/help?id=log-to-different-streams
{ level: 'debug', stream: process.stdout },
{ level: 'error', stream: process.stderr },
{ level: 'fatal', stream: process.stderr },
],
{ dedupe: true },
),
],
};