I was struggling with this same problem time ago. The problem I found with your approach is that you need to pass the request object all over your code, which gets it dirty.
Finally, I made a wrap of Winston logger library, and used another libraries for sharing variables withoug passing them through function calls, and it works pretty well. The library generate and manage a unique request Id and print it with every log, so you can abstract from this problem.
Hope it helps: github.com/davicente/express-logge...
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
I was struggling with this same problem time ago. The problem I found with your approach is that you need to pass the request object all over your code, which gets it dirty.
Finally, I made a wrap of Winston logger library, and used another libraries for sharing variables withoug passing them through function calls, and it works pretty well. The library generate and manage a unique request Id and print it with every log, so you can abstract from this problem.
Hope it helps:
github.com/davicente/express-logge...