Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to use winston logging and debug module together?

I use winston logging because I use its features like different logging levels, multiple transports, etc.

But I also like debug's namespace feature. Besides, express already uses it. So is it possible to use them together, e.g. to let winston logging have namespace?

like image 972
Qiulang 邱朗 Avatar asked Oct 30 '17 10:10

Qiulang 邱朗


1 Answers

After using several different loggers I gain more insight about nodejs loggers, now I believe they are not supposed to be used together b/c they are designed for different purposes. On the other hand, morgan and winston can be used together, e.g. Node.js - logging / Use morgan and winston, morgan and debug can be used together too, Nodejs - How to use morgan with debug

But first of all, to quote from Logging in Node.js done right

Setting up proper logging in Node.js applications can be bit overwhelming at first due to the plethora of modules available through NPM.

That was indeed my situation when I had morgan, winston, debug together. But then I realized they are for different purposes with overlaps. So I use debugjs when I really debug an issue instead of using console.log(some said debugjs is not a logger). After I am done with it I turn that debug off.

Morgan is to log express HTTP request specifically. Better to use it in dev/prod env for different purposes.

Using different log levels for Winston in dev/prod env is probably a common practice. I can also use express-winston to log HTTP request instead of using morgan.

Winston uses a different log level to turn off some log, unlike debugjs to use namespace to turn log off so I don't think they can work together.

--- update 2021 ---

Since I first answered my own question in 2018, I was asked several times about the log level related question. I found an issue opened against debugjs confirmed what I said about debug, to quote the answer from its current maintainer

Debug isn't a general purpose logging library, it's meant to conditionally turn on debug logs. There is no concept of log levels. Instead, break up your namespaces into different components and enable the ones you care about

like image 69
Qiulang 邱朗 Avatar answered Oct 23 '22 08:10

Qiulang 邱朗