I am using winston to make a self logger, which allow me to add the timestamps and line number in the logging. The code can accomplish the functionality each, but when combined, they don't work as expected.
// **help to add timestamp**
var logger = new (winston.Logger)({
transports : [new (winston.transports.Console)({
json : false,
timestamp : true,
colorize: true
}), new winston.transports.File({
filename : __dirname + '/debug.log',
json : true
})]
,exitOnError : false
});
// **help me to add line number**
var logger_info_old = winston.info;
logger.info = function(msg) {
var fileAndLine = traceCaller(1);
return logger_info_old.call(this, fileAndLine + ":" + msg);
}
However, when line number configuration is added, timestamp for the logging will disappear.
For example, before adding the line number configuration.
logger.info("abc");
2013-11-24T09:49:15.914Z - info:339:abc
when adding the line number configuration
logger.info("abc");
info: (H:\Dropbox\node\fablab\utils\logging.js:85:abc
The optimal result i want is like
logger.info("abc");
2013-11-24T09:49:15.914Z - info: (H:\Dropbox\node\fablab\app.js:339:abc
Can I fix this?