-
Notifications
You must be signed in to change notification settings - Fork 940
Open
Labels
Description
Currently, when providing a custom serializer we need to build an object that is later stringified by pino. This is a bit inefficient in certain cases. It would be nice if a serializer could somehow return a string which then pino uses directly as if it got an object that it then stringifies.
Consider the following example when using undici:
class Handler {
onHeaders(statusCode, rawHeaders: Array<string>, resume) {
logger.debug({ statusCode, headers: rawHeaders })
}
}
slowSerializers = {
headers: headers => {
const ret = {}
for (let n = 0; n < headers.length; n += 2) {
ret[headers[n + 0].toString()] = headers[n + 1].toString()
}
return ret
}
}
fastSerializers = {
headers: headers => {
const ret = '{'
for (let n = 0; n < headers.length; n += 2) {
ret += n > 0 ? ',' : ''
ret += `"${headers[n + 0]}": "${headers[n + 1]}"`
}
return ret + '}'
}
}Reactions are currently unavailable