1
0
Fork 0
mirror of synced 2024-07-15 19:25:55 +12:00

Honor level on logging

This commit is contained in:
Adria Navarro 2023-07-21 17:52:54 +02:00
parent 0ac639fe7a
commit d168a0b902

View file

@ -12,11 +12,12 @@ import { localFileDestination } from "../system"
let pinoInstance: pino.Logger | undefined let pinoInstance: pino.Logger | undefined
if (!env.DISABLE_PINO_LOGGER) { if (!env.DISABLE_PINO_LOGGER) {
const level = env.LOG_LEVEL
const pinoOptions: LoggerOptions = { const pinoOptions: LoggerOptions = {
level: env.LOG_LEVEL, level,
formatters: { formatters: {
level: label => { level: level => {
return { level: label.toUpperCase() } return { level: level.toUpperCase() }
}, },
bindings: () => { bindings: () => {
if (env.SELF_HOSTED) { if (env.SELF_HOSTED) {
@ -33,14 +34,22 @@ if (!env.DISABLE_PINO_LOGGER) {
timestamp: () => `,"timestamp":"${new Date(Date.now()).toISOString()}"`, timestamp: () => `,"timestamp":"${new Date(Date.now()).toISOString()}"`,
} }
const destinations: pino.DestinationStream[] = [] const destinations: pino.StreamEntry[] = []
destinations.push( destinations.push(
env.isDev() ? pinoPretty({ singleLine: true }) : process.stdout env.isDev()
? {
stream: pinoPretty({ singleLine: true }),
level: level as pino.Level,
}
: { stream: process.stdout, level: level as pino.Level }
) )
if (env.SELF_HOSTED) { if (env.SELF_HOSTED) {
destinations.push(localFileDestination()) destinations.push({
stream: localFileDestination(),
level: level as pino.Level,
})
} }
pinoInstance = destinations.length pinoInstance = destinations.length