如何从winston @ 3记录器输出中删除[Symbol]字段?

时间:2018-07-17 09:44:41

标签: node.js logging winston

这是winston @ 3记录器的演示代码:

const { createLogger, format, transports } = require("winston")
const { combine, timestamp, prettyPrint } = format

const logger = createLogger({
  format: combine(timestamp(), prettyPrint({ colorize: true }))
})

logger.add(new transports.Console())

logger.info("test message", { data: { a: 1, b: [1, 2, 3, 4], d: new Date() } })

它打印:

{ data: { a: 1, b: [ 1, 2, 3, 4 ], d: 2018-07-17T09:38:43.253Z },
  level: 'info',
  message: 'test message',
  timestamp: '2018-07-17T09:38:43.253Z',
  [Symbol(level)]: 'info',
  [Symbol(splat)]:
   [ { data: { a: 1, b: [ 1, 2, 3, 4 ], d: 2018-07-17T09:38:43.253Z } } ] }

我想从输出中删除一些字段:[Symbot(level)],[Symbot(splat)],所以我想要这样的输出:

{ data: { a: 1, b: [ 1, 2, 3, 4 ], d: 2018-07-17T09:38:43.253Z },
  level: 'info',
  message: 'test message',
  timestamp: '2018-07-17T09:38:43.253Z' }

1 个答案:

答案 0 :(得分:0)

您可以修改日志输出及其格式。这是官方文档:https://github.com/winstonjs/winston#streams-objectmode-and-info-objects

这里是示例:

logger.add(winston.transports.Console, {
    level       : 'error',
    prettyPrint : true,
    silent      : false,
    timestamp   : true,
    json        : false
});