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

Add extra metada into log record #680

Open
akravets opened this issue Jan 13, 2022 · 1 comment
Open

Add extra metada into log record #680

akravets opened this issue Jan 13, 2022 · 1 comment

Comments

@akravets
Copy link

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?

@gratus-acuitymd
Copy link

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

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