nestjs winston 日志文件是用颜色编码编写的

nestjs winston log file is written with colors encoding

我面临与 https://github.com/winstonjs/winston/issues/1416 相同的问题,其中 logger.info('Hello there. How are you?'); 导致 �[32minfo�[39m: �[32mHello there. How are you?�[39m

我不知道 colorize 在哪里,所以我可以删除它,这是我的代码:

  new winston.transports.File({
    format: winston.format.combine(
      winston.format.colorize({ // I added this but it's still not helping
        all: false,
        message: false,
        level: false,
      }),
      winston.format.label({ label: 'API' }),
      winston.format.timestamp(),
      winston.format.printf(({ level, message, label, timestamp }) => {
        return `${timestamp} [${label}] ${level}: ${message}`;
      }),
    ),
    filename: environment.logDirectory,
    level: 'http',
    maxsize: 1024 * 1024 * 10,
  }),

main.ts,我有

import { WINSTON_MODULE_NEST_PROVIDER } from 'nest-winston';
app.useLogger(app.get(WINSTON_MODULE_NEST_PROVIDER));

AppModule.ts中,我有以下内容:

import { WinstonModule } from 'nest-winston';
...
    WinstonModule.forRoot({
      transports,
    }),

我找不到任何使用 colorize() 的地方,我不知道如何禁用它。

我正在使用 "nest-winston": "^1.4.0","winston": "^3.3.3",

winston.format.uncolorize() 方法添加到格式化选项以从您的 winston 输出中去除颜色编码

  format: winston.format.combine(
     winston.format.uncolorize()
     ...

干杯