-
Notifications
You must be signed in to change notification settings - Fork 875
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Error Object Serialisation issue with nestedKey
options
#771
Comments
I think you'll need to add a serializer for the |
I am running into a similar issue with API responses. When I upgrade to pino@5.16.0 and use the If I remove the
Here is what the
Here are the libraries that I am using
|
I was able to identify where the issue is. The code checks if the https://github.com/pinojs/pino/blob/master/lib/tools.js#L37 The problem is that when the code tries to run the serializers against the object, the https://github.com/pinojs/pino/blob/master/lib/tools.js#L94 I'm looking into a possible fix now |
Yes, that was the point of #759 By enabling the Serializers work by inspecting the root level of the log object, e.g. the Thus my response that you will need to define a new serializer to accommodate whatever key you specified as the nesting key. |
Thanks for the quick response and being so thorough in the explanation! It makes complete sense now. I was able to get the desired output by using the following options with the default pino serializers.
As for my part of this issue, I feel that the issue is resolved. Do you think that that adding to the documentation about the use of |
Better documentation is always welcome. |
I'm closing this as I believe it has been sufficiently answered. |
Thanks @VtoCorleone your code snippet helped me to workaround this. For reference, I also added a conditional to support directly logging out an error object, i.e. nestedKey: 'payload',
serializers: {
payload: data => {
if(data instanceof Error) {
return pino.stdSerializers.err(data.err);
}
if (data.req) {
data.req = pino.stdSerializers.req(data.req);
}
if (data.res) {
data.res = pino.stdSerializers.res(data.res);
}
if (data.err) {
data.err = pino.stdSerializers.err(data.err);
}
return data;
}
} |
A helpful note for whoever finds this, note that the first check for an error here should just pass the error instead of data.err. if (data instanceof Error) {
return pino.stdSerializers.err(data);
} |
There's still problem. By adding serializers for nestedKey, the error object is well printed. But the |
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. |
Error object information is not serialized/included when
nestedKey
option is providedCode
Output
The text was updated successfully, but these errors were encountered: