trentm/node-bunyan

Custom fields always part of a log message

Ankan-Fraedom opened this issue · 1 comments

Hi there, using this awesome logging framework, so thanks a lot for creating and maintaining. Just wondering is it possible to add a custom filed in bunyan which will always appear no matter what I log. Like a requestId appearing always in the log message like a Pid, date etc. would be awesome. Please let me know. Cheers.

Yes, that is the default behaviour for all fields other than a few special ones. See https://github.com/trentm/node-bunyan/#constructor-api or, for example:

var log = bunyan.createLogger({name: 'myapp', requestId: genRequestId});

log.info('hi'); // This log record will have 'name' and 'requestId' fields per the constructor above.