I just implemented Winston Logging and it works as expected but i came accross a few issues which i cant find answer for.
The way winston works as far as i can tell, the set log level and anything below as far as priority gets used, like on error it will also include info logs etc. Is there a way to create a specific log level lets call it HTTP or db where i only log http or db events to and they don't end up in the combined file or console ?
A better solution is to use a single logger with a format function as a "level filter" to specify which transport logs which specific level. Here is the solution (note,
levelFilter
could easily be extended to take an array of acceptable levels).The key insight is that if no
info
object is returned from the formatter chain, nothing gets logged.I can init a winston with a parameter, in your case filename. I use similar setup for logging separated cron tasks (I use
type
parameter insteadfilename
, which is used as a prefix in log, so I can identify problems in multiple cron tasks in one log file). I hope you are familiar with ES6 syntax.utils/winston.js
So in a your code you can import custom winston setup from utils and initialize it with a filename. Be careful, I basically export only error function from winston
errorLogger(filename).error
, You can modify it in way acceptable for youmain.js