Skip to content
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 serializer custom context #26

Closed
ecdeveloper opened this issue Nov 1, 2019 · 1 comment
Closed

Error serializer custom context #26

ecdeveloper opened this issue Nov 1, 2019 · 1 comment

Comments

@ecdeveloper
Copy link

I'm trying to log an error object, that has some extra context. The error serializer ignores anything but type, message and stack. Would you consider extending the error serializer to make it hydrate the resulting _err object with the extra fields it may have? Or should I rather use the pino-std-serializers directly, serialize my error object directly, then hydrate it and then pass it to pino?

Example:

const logger = pino();

const err = new Error('Boom!');
err.foo = 'bar';

// Expecting to see `foo: bar` logged here, but it's not
logger.error(err);

Here's the interim solution I have:

const stdSerializers = require('pino-std-serializers');
const logger = pino();

// Assuming this error is created in a separate file, and passed into this file as an argument
const err = new Error('Boom!');
err.foo = 'bar';

const serializedErr = stdSerializers.err(err);
serializedErr.foo = err.foo;

pino.error(serializedErr);
@mcollina
Copy link
Member

mcollina commented Nov 1, 2019

I'm a bit puzzled, the serializer should be applied automatically. Have you tried calling logger.error({ err }) instead?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants