-
Notifications
You must be signed in to change notification settings - Fork 17
How to pass custom data in all lines? #17
Comments
After passportJS middleware is run, you can add another middleware creating a new child logger adding the userId: req.logger = req.logger.child({ userId }) |
@mcollina I tried that, I did a middleware:
I get one message with user_id:
And another one, generated by ExpressJs, without user_id:
I need to ExpressJs messages be generated with user_id too. |
in which cases is not printing |
@mcollina this 2 messages happens in one request.
When I get a request, I get 2 messages, one with user_id and another one without it:
The second message, 'request completed' is generated automatically by Express and it seems that internally Express use another instance of logger, not req.log. |
My bad: you need to override also the instance in res.log, as that is the one used by that message. |
Yes, is works: |
I use PassportJS and I want to insert in logs id of logger user. User is stored in req.user object.
How to add req.user.id in any log lines?
I tried to use serializers, but req serializer runs before passportjs, so req.user is not defined at that time.
The text was updated successfully, but these errors were encountered: