node-bunyan icon indicating copy to clipboard operation
node-bunyan copied to clipboard

Add extra metada into log record

Open akravets opened this issue 4 years ago • 1 comments

Hello,

Currently I am only aware of doing this using serializers: logger.error({ req: request, err: err }, "message");

I'd like to achieve this without needing to pass request object to each log call, but rather set this data when logger is initialized and appear in logs when log is called:

logger = require("lgger") logger.setId(req.getId()) logger.info("test")

// INFO - 55 - test

Doesn't have to be the exact approach, but some variation of this. Would this be possible with child log feature?

akravets avatar Jan 13 '22 01:01 akravets

I think you can do this with

const child = logger.child({requestId: req.getId()});
child.info("something");

That should now include requestId see https://github.com/trentm/node-bunyan#logchild

jnanajneya avatar Dec 14 '22 17:12 jnanajneya