简体   繁体   English

使用Winston使用Express Node.js进行日志记录

[英]logging with Express Node.js using winston

I have my logging configured like this in my express/nodejs web application. 我在express / nodejs Web应用程序中将日志记录配置如下。 The timestamp in the log messages are in GMT. 日志消息中的时间戳记为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

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
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM