This article is great for what you want to do.
http://tostring.it/2014/06/23/advanced-logging-with-nodejs/
For your specific code, you probably need something like this:
var logger = new winston.Logger({ transports: [ new winston.transports.File({ level: 'info', filename: './logs/all-logs.log', handleExceptions: true, json: true, maxsize: 5242880, //5MB maxFiles: 5, colorize: false }), new winston.transports.Console({ level: 'debug', handleExceptions: true, json: false, colorize: true }) ], exitOnError: false }), logger.stream = { write: function(message, encoding){ logger.info(message); } }; app.use(require("morgan")("combined", { "stream": logger.stream }));
This will install Winston to write the log to the console as well as to the file. You can then use the last expression to pass the output from morgan middleware to winston.
lindsaymacvean Mar 03 '15 at 5:03 2015-03-03 05:03
source share