How to add module or file names for log lines in winston?
Apr 23, 2024
Every application I have shipped in past 15 years had logging enabled in one way or another. The 12 Factor App also mentions importance of logging. In node.js applications I have been using Winston as a logging package. Unlike Java or PHP logging package managers, getting module name or file name in logs was not straightforward. Here is how I do it:
For obvious reasons, do not just copy paste. I am using a JSON format, you may not need it. Add ๐ง per your taste and enjoy!