node-bunyan
node-bunyan copied to clipboard
Add extra metada into log record
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?
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