Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

nodejs and logging through different modules

I'm just interested in the best approach to the following...

I have an app that is split into a few modules for maintenance reasons and separation of concerns. I want to be able to create a log file when my app starts and then using the different modules I have written write to the same log file without it becoming messy and having unneeded code in my exported modules.

Thanks in advance.

like image 357
Julio Avatar asked Jan 01 '12 11:01

Julio


People also ask

Does logging affect performance Nodejs?

We already know that logging is affecting performance, especially when we use console. log because its a syncronous process. In nodejs, we have to use asyncronous process to get the best performance.

Why do you need separate modules in node JS?

Each module in Node. js has its own context, so it cannot interfere with other modules or pollute global scope. Also, each module can be placed in a separate . js file under a separate folder.


1 Answers

Use Winston for logging, it can log in a file, db, anything and it has a good documentation. You can use Winston to log messages across all of your modules.

like image 174
alessioalex Avatar answered Sep 21 '22 17:09

alessioalex