Merge pull request #11318 from Budibase/BUDI-7113/fix_overriding_service_name
Pino logging tweaks
This commit is contained in:
commit
cd5f82f712
1 changed files with 25 additions and 10 deletions
|
@ -12,29 +12,44 @@ 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) {
|
||||||
|
// "service" is being injected in datadog using the pod names,
|
||||||
|
// so we should leave it blank to allow the default behaviour if it's not running self-hosted
|
||||||
return {
|
return {
|
||||||
service: env.SERVICE_NAME,
|
service: env.SERVICE_NAME,
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
return {}
|
||||||
|
}
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
timestamp: () => `,"timestamp":"${new Date(Date.now()).toISOString()}"`,
|
timestamp: () => `,"timestamp":"${new Date(Date.now()).toISOString()}"`,
|
||||||
}
|
}
|
||||||
|
|
||||||
const destinations: pino.DestinationStream[] = []
|
const destinations: pino.StreamEntry[] = []
|
||||||
|
|
||||||
if (env.isDev()) {
|
destinations.push(
|
||||||
destinations.push(pinoPretty({ singleLine: true }))
|
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
|
||||||
|
|
Loading…
Reference in a new issue