如何将 winston 与 simple() 结合使用来获得自定义输出?

How can I get a custom output using winston in combination with simple()?

我正在尝试使用 winston 获取以下格式:2020-01-01 [INFO]: test 将关卡部分着色,但我得到的是

info: test

如何获得我正在寻找的格式?

import winston from "winston";

const format = winston.format.combine(
  winston.format.align(),
  winston.format.colorize(),
  winston.format.errors({ stack: true }),
  winston.format.printf(
    ({ level, message }) => `[${level.toUpperCase()}]: ${message}`
  ),
  winston.format.simple(),
  winston.format.timestamp({ format: "YYYY-MM-DD HH:mm:ss" })
);

export const logger = winston.createLogger({
  level: process.env.NODE_ENV === "production" ? "info" : "debug",
  transports: [new winston.transports.Console({ format })],
});

使用以下方法修复

import winston from "winston";

const format = winston.format.combine(
  winston.format(info => ({ ...info, level: info.level.toUpperCase() }))(),
  winston.format.align(),
  winston.format.colorize(),
  winston.format.errors({ stack: true }),
  winston.format.prettyPrint(),
  winston.format.simple(),
  winston.format.splat(),
  winston.format.timestamp({ format: "YYYY-MM-DD HH:mm:ss" }),
  winston.format.printf(
    ({ timestamp, level, message }) => `${timestamp} [${level}]: ${message}`
  )
);

export const logger = winston.createLogger({
  level: process.env.NODE_ENV === "production" ? "info" : "debug",
  transports: [new winston.transports.Console({ format })],
});