building5 / sails-hook-bunyan

Bunyan integration for Sails
MIT License
5 stars 3 forks source link

Logged objects are being stringified into msg #10

Closed robertrossmann closed 9 years ago

robertrossmann commented 9 years ago

When I try to log an object with some properties, the object is stringified and appended to the log message, instead of the object's properties becoming part of the log data. Here is an example to illustrate this:

sails.log.info('user data', { user: { prop: true } })
// Note the msg property
{"name":"sails","hostname":"localhost.local","pid":11040,"level":30,"msg":"user data Object { user: Object { prop: true } }","time":"2015-10-22T21:00:22.412Z","v":0}

According to Bunyan logs, the object data should be merged into the log object itself, not stringified. Is there something I need to do to enable that behaviour? I am not providing any custom configuration options.

Thanks for help!

leedm777 commented 9 years ago

@Alaneor That's bunyan's behavior. The object should be before the message, not after.

I agree that it's totally confusing behavior, though. There's probably already an issue/discussion about this at trentm/node-bunyan.

> var bunyan = require('bunyan')
undefined
> var log = bunyan.createLogger({name: 'foo'})
undefined
> log.info('after', { foo: 'bar'})
{"name":"foo","hostname":"dlee-mac.local","pid":51461,"level":30,"msg":"after { foo: 'bar' }","time":"2015-10-22T21:29:50.292Z","v":0}
undefined
> log.info({foo: 'bar'}, 'before')
{"name":"foo","hostname":"dlee-mac.local","pid":51461,"level":30,"foo":"bar","msg":"before","time":"2015-10-22T21:30:04.135Z","v":0}
undefined
robertrossmann commented 9 years ago

Hi, thanks for the tip! It seems, though, that the behaviour is still the same even if I use the object as first argument:

sails.log.info({ user: { prop: true } }, 'user data')
{"name":"sails","hostname":"localhost.local","pid":11115,"level":30,"msg":"Object { user: Object { prop: true } } user data","time":"2015-10-22T21:33:30.492Z","v":0}
leedm777 commented 9 years ago

Oops. I tried to 'be nice' and use the log config hooks provided by Sails, but it appears that they squash all the arguments into a string before passing off to the logger.

Should be fixed in v2.1.4

robertrossmann commented 9 years ago

Awesome, thank you!