[Question] How can I use redaction with a transport?
Opened this issue · 2 comments
vedantroy commented
I have the following setup with logtail:
let logger = pino({
redact: {
// these are just clutter
paths: ['pid', 'hostname'],
remove: true
}
})
if (LOGTAIL_SOURCE_TOKEN) {
logger = pino.transport({
target: "@logtail/pino",
options: {
sourceToken: LOGTAIL_SOURCE_TOKEN,
},
})
}
I am wondering how I can use the redaction feature with the transport. Is there a place I can pass in the options?
Additionally, I was wondering how can I could make all calls to the logger
- log to a place like logtail
- log to the terminal using a pretty syntax (instead of JSON)
vedantroy commented
This is what I came up with, will see if it works:
type PinoOpts = Parameters<typeof pino>[0] & { transport: TransportMultiOptions & { targets: TransportTargetOptions[] } }
const opts: PinoOpts = {
redact: {
// these just cause clutter
paths: ["pid", "hostname"],
remove: true,
},
transport: {
targets: []
}
}
if (LOGTAIL_SOURCE_TOKEN) {
opts.transport.targets.push({
level: "trace",
target: "@logtail/pino",
options: {
sourceToken: LOGTAIL_SOURCE_TOKEN,
},
})
}
opts.transport.targets.push({
level: "trace",
target: "@mgcrea/pino-pretty-compact",
options: {
translateTime: "HH:MM:ss Z",
}
})
mcollina commented
looks great!