pino
pino copied to clipboard
Functions stored in array will be shown as nulls
We have some abstract method in class, like this:
class SomeClass {
constructor() {
this.dataListeners = {};
}
someAbstractMethod (topic, eventFn) {
if (!Array.isArray(this.dataListeners[topic])) {
this.dataListeners[topic] = [];
...
}
...
this.dataListeners[topic].push(eventFn);
this.logger.info('Listeners to topic', this.dataListeners[topic]); // --> output is { ...,"msg":"Listeners to topic [null]","v":1}
return this;
}
}
this.dataListeners[topic]
actually stores the functions, but somehow pino interpreters those as nulls.
Same message shown via console.log()
is proper:
Listeners to topic [ [Function: onIncomingTask] ]
What am I doing wrong?
Half day stuck because of these nulls in logged arrays!
the msg text should be fixed to ease processing/searching.
Add those as a property.
log.info({ hello: “world” }, “some log line”)
I don’t recall if we did this for some purpose or not, there were definitely some differences in interpolation. Maybe would you like to send a PR? What do you think @davidmarkclements?
this is something we can improve in the mean time a workaround for this scenario would be to convert the functions to strings yourself
this.logger.info('Listeners to topic', this.dataListeners[topic].map(({name}) => `[Function: ${name}]`));
Stumbled across this today, is there any other workaround than the one david mentioned above? Having to do this in every log is quite cumbersome expecially when using typescript as I want to print out whole objects and and data mangling them to print out function names is quite a hassle tbh :thinking:
Use a hook -- https://github.com/pinojs/pino/blob/613d700fc2b77768bbbc84095a5cc28fb745b10d/docs/api.md#logmethod
Use a hook -- https://github.com/pinojs/pino/blob/613d700fc2b77768bbbc84095a5cc28fb745b10d/docs/api.md#logmethod
Resolved by this.
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.