片刻不适用于winston.transports.File

时间:2018-04-16 06:40:32

标签: javascript node.js winston

从下面的帖子我有想法用winston改变日期格式。

winston:how to change timestamp format

但这适用于winston.transports.Console,而不适用于winston.transports.File

PFB我的代码:

var logger = new winston.Logger({
    level: 'debug',
    timestamp: function () {
      return moment().format('YYYY-MM-DD hh:mm:ss')
    },
    transports: [
          new(winston.transports.MongoDB)({
                  db : 'dbpath',
                  collection : 'Logs',
                    level : 'error',
                    capped : true,
                    timestamp: function () {
                      return moment().format('YYYY-MM-DD hh:mm:ss')
                    }

          }),
          new winston.Logger({
            level: 'debug',
            transports: [
              new(winston.transports.File)
              ({ filename: 'filename' })
            ],
            timestamp: function () {
              return moment().format('YYYY-MM-DD hh:mm:ss')
            }
          }),
          new winston.transports.Console({

            timestamp: function () {
              return moment().format('YYYY-MM-DD hh:mm:ss')
            }

          })
    ]
})

我在输出文件中得到了这个:

{"level":"info","message":"info Hello","timestamp":"2018-04-16T06:42:12.819Z"}
{"level":"error","message":"error Hello","timestamp":"2018-04-16T06:42:12.847Z"}
{"level":"debug","message":"debug Hello","timestamp":"2018-04-16T06:42:12.861Z"}
{"level":"warn","message":"debug Hello","timestamp":"2018-04-16T06:42:12.900Z"}

它既没有为mongodb运输工作

0 个答案:

没有答案