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

Log API: How to separate the summary and detail text? #237

Closed
myndzi opened this issue Mar 24, 2015 · 2 comments
Closed

Log API: How to separate the summary and detail text? #237

myndzi opened this issue Mar 24, 2015 · 2 comments

Comments

@myndzi
Copy link

myndzi commented Mar 24, 2015

I'm trying to do something like this:

log.info('Message', {
    // json data
});

And I want the result to be something like this:

{
    msg: 'Message',
    // don't really care how the rest is separated out
}

But I'm observing that in the output, I get the message squashed into the json data without a newline or anything: 'Message { json data }'

I've tried using something like this:

log.info({
    msg: 'Message',
    detail: {
        // json data
    }
});

But when I do that, 'msg' is blank for some unknown reason. I've looked at the docs but they don't seem to be clear on how to deal with this scenario, but you can see that logging say, an Error object, produces precisely the behavior I want. How can I do this with arbitrary data?

@jburnham
Copy link

The api says you need to pass the object you want to serialize as the first argument and then you can specify a message. Try this:

log.info({
    // json data
}, 'Message');

This will output

{
    msg: 'Message',
    // don't really care how the rest is separated out
}

@myndzi
Copy link
Author

myndzi commented May 19, 2015

Haha, so simple. I had forgotten about this, thanks for getting back.

This ordering is confusing because of the way message interpolation happens, e.g. log.info('foo %s', fooVal); I didn't even consider putting the message "last". It makes sense under consideration, though it still seems a bit awkward.

@myndzi myndzi closed this as completed May 19, 2015
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