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 inconsistency #426

Closed
DonutEspresso opened this issue Jul 26, 2016 · 2 comments
Closed

Error serializer inconsistency #426

DonutEspresso opened this issue Jul 26, 2016 · 2 comments

Comments

@DonutEspresso
Copy link

There seems to be a minor inconsistency with the error serializer. Given the following:

var VError = require('verror');
var bunyan = require('bunyan');

var log = bunyan.createLogger({
    name: 'foo',
    serializers: bunyan.stdSerializers
});

var wrapErr = new VError(new Error('boom'), 'boom2!');

log.error(wrapErr);
log.error({ err: wrapErr });

The output produced is:

[2016-07-26T01:14:08.105Z] ERROR: foo/34618 on lgml-aliu: boom2!: boom
    VError: boom2!: boom
        at Object.<anonymous> (/Users/aliu/Downloads/test/log.js:9:15)
        at Module._compile (module.js:409:26)
        at Object.Module._extensions..js (module.js:416:10)
        at Module.load (module.js:343:32)
        at Function.Module._load (module.js:300:12)
        at Function.Module.runMain (module.js:441:10)
        at startup (node.js:139:18)
        at node.js:968:3
    Caused by: Error: boom
        at Object.<anonymous> (/Users/aliu/Downloads/test/log.js:9:26)
        at Module._compile (module.js:409:26)
        at Object.Module._extensions..js (module.js:416:10)
        at Module.load (module.js:343:32)
        at Function.Module._load (module.js:300:12)
        at Function.Module.runMain (module.js:441:10)
        at startup (node.js:139:18)
        at node.js:968:3
[2016-07-26T01:14:08.108Z] ERROR: foo/34618 on lgml-aliu:
    VError: boom2!: boom
        at Object.<anonymous> (/Users/aliu/Downloads/test/log.js:9:15)
        at Module._compile (module.js:409:26)
        at Object.Module._extensions..js (module.js:416:10)
        at Module.load (module.js:343:32)
        at Function.Module._load (module.js:300:12)
        at Function.Module.runMain (module.js:441:10)
        at startup (node.js:139:18)
        at node.js:968:3
    Caused by: Error: boom
        at Object.<anonymous> (/Users/aliu/Downloads/test/log.js:9:26)
        at Module._compile (module.js:409:26)
        at Object.Module._extensions..js (module.js:416:10)
        at Module.load (module.js:343:32)
        at Function.Module._load (module.js:300:12)
        at Function.Module.runMain (module.js:441:10)
        at startup (node.js:139:18)
        at node.js:968:3

In the second log statement using the { err: err } format, the first line is missing the error message. Ultimately a minor inconsistency issue, but since the error message is color coded it can help with readability.

@trentm trentm closed this as completed in 0974231 Aug 26, 2016
@trentm
Copy link
Owner

trentm commented Aug 26, 2016

Ah, nice catch, thanks. This goes way back (a special case added for log.info(err)). I agree that log.info({err: err}) should be equivalent. Fixed in the commit above.

@DonutEspresso
Copy link
Author

Thanks! 👍

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

No branches or pull requests

2 participants