I'm working on a node application with multiple modules. I am now trying to setup logging properly (should have done so at the start), and looking at using Bunyan.
Would it be better to have a single logger
module that is exported and then required by the other modules, as suggested in this answer or define a new bunyan logger
instance in each module directly and configure it accordingly? For reuse I imagine the former, but I don't know if this would be restrictive going forward.
If I have a single logger defined like
var bunyan = require('bunyan');
var logger = bunyan.createLogger({
name: "filter",
streams: [
{
level: 'info',
stream: process.stdout
},
{
level: 'error',
path: '../error.log'
},
{
level: 'debug',
path: '../debug.log'
}
]
});
module.exports = logger;
Then all the modules that make use of it would also be logging with the name filter
, whereas it might make more sense for each module to log to a name that better represents itself.
Also, am I right in thinking that all modules should log errors to the same log file e.g. systemErr.log (to allow a better overview) or should they log to their own error logs, e.g. module1Err.log, module2Err.log?