logging with Express Node.js using winston

2.8k views Asked by At

I have my logging configured like this in my express/nodejs web application. The timestamp in the log messages are in GMT. Is there a way to get the local time instead?

var winston = require('winston');
winston.emitErrs = true;

var logger = new winston.Logger({
  transports: [
    new winston.transports.File({
        level: 'debug',
        filename: './logs/all-logs.log',
        handleExceptions: true,
        json: false,
        maxsize: 5242880, //5MB
        maxFiles: 5,
        colorize: false,
        timestamp:true
    }),
    new winston.transports.Console({
        timestamp :true,
        level: 'debug',
        handleExceptions: true,
        json: false,
        colorize: true
    })
],
exitOnError: false
});

module.exports = logger;
module.exports.stream = {
    write: function(message, encoding){
        logger.info(message);
    }
};

This is a sample log out put I get

2014-11-18T18:30:33.570Z - debug: Authenticated
1

There are 1 answers

2
Tug On

Have you tried with :

function myTimestamp() {
  return new Date().toString();
};

var logger = new winston.Logger({
  transports: [
    new winston.transports.File({
        level: 'debug',
        filename: './logs/all-logs.log',
        handleExceptions: true,
        json: false,
        maxsize: 5242880, //5MB
        maxFiles: 5,
        colorize: false,
        timestamp: myTimestamp
    }),
    new winston.transports.Console({
        timestamp :true,
        level: 'debug',
        handleExceptions: true,
        json: false,
        colorize: true
    })
],
exitOnError: false
});