How to add module or file names for log lines in winston?

Kumar Chetan Sharma
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!

--

--

Kumar Chetan Sharma

C0d3๐Ÿต from ๐Ÿ‡ฎ๐Ÿ‡ณ. selfTaught. ๐Ÿ˜จ of CS, Algos & DS. World famous ๐Ÿ‘จโ€๐Ÿณ at home. Pro Level Pro-Crastinator. Man child. Dad of (โœฟโ— โ€ฟโ— )(โ— โ€ฟโ— โœฟ)