generated from lokalise/node-service-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
logger.ts
28 lines (26 loc) · 761 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
import type { PinoLoggerOptions } from 'fastify/types/logger'
import { levels } from 'pino'
import type { AppConfig } from './config.js'
import { isProduction } from './config.js'
export function resolveLoggerConfiguration(appConfig: AppConfig): PinoLoggerOptions | boolean {
const config: PinoLoggerOptions = {
level: appConfig.logLevel,
formatters: {
level: (_label, numericLevel): { level: string } => {
const level = levels.labels[numericLevel] || 'unknown'
return { level }
},
},
}
if (!isProduction()) {
config.transport = {
target: 'pino-pretty',
options: {
colorize: true,
translateTime: 'SYS:standard',
ignore: 'hostname,pid',
},
}
}
return config
}