Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why use both `morgan` and `debug` logging packages in one project

I've just created an app from express generator and it uses two loggers debug and morgan:

/bin/www.js

const debug = require('debug')('myapp:server');
....
server.on('listening', onListening);
function onListening() {
    const addr = server.address();
    const bind = typeof addr === 'string'
        ? 'pipe ' + addr
        : 'port ' + addr.port;
    debug('Listening on ' + bind);
 --^^^^^^^--
}

/app.js

var logger = require('morgan');
...
app.use(logger('dev'));

Why use both? Can't only one of them be used for both purposes?

like image 811
Max Koretskyi Avatar asked Dec 29 '16 16:12

Max Koretskyi


1 Answers

morgan is a library you typically attach as middleware, and then it automatically logs information as requests flow through your system, especially in regards to timing it seems. I don't believe it is something you would typically invoke manually for additional logging.

debug is something you would add in manually with additional information that morgan doesn't necessarily know or care about. You can also turn debug logging on and off through the use of a regular expression in an environment variable, which is useful for limiting namespaced logs down to the ones you care about when debugging an issue. See here.

So sure, you could use debug to log the same way and the same things morgan does, but you'd have to do it all by hand (for better or worse).

like image 123
dvlsg Avatar answered Oct 10 '22 03:10

dvlsg