which is the best way to enable logging in node , express , mongoose application? I have been using console logging ;but there is no way to turn it on or off during production. is there something as solid as log4j and can be used in production applications
You can use winston.js, https://github.com/winstonjs/winston#logging-levels You can use log levels and specify which level to log in console and which into some logfile
var logger = new (winston.Logger)({
transports: [
new (winston.transports.Console)({ level: 'error' }),
new (winston.transports.File)({
filename: 'somefile.log',
level: 'info'
})
]
});
But there is also log4js https://github.com/nomiddlename/log4js-node
You can install morgan,
Use npm install morgan,
After installing it,require it i.e
var morgan = require('morgan');
Since you have express installed,
You can then do this to enable morgan,
app.use(morgan('dev'));
This should work.