Nestjs Winston 日志文件是用颜色编码编写的

Dom*_*Dom 1 winston nestjs express-winston

我面临与https://github.com/winstonjs/winston/issues/1416相同的问题,结果logger.info(\'Hello there. How are you?\');\xef\xbf\xbd[32minfo\xef\xbf\xbd[39m: \xef\xbf\xbd[32mHello there. How are you?\xef\xbf\xbd[39m

\n

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

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

在 中main.ts,我有

\n
import { WINSTON_MODULE_NEST_PROVIDER } from \'nest-winston\';\napp.useLogger(app.get(WINSTON_MODULE_NEST_PROVIDER));\n
Run Code Online (Sandbox Code Playgroud)\n

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

\n
import { WinstonModule } from \'nest-winston\';\n...\n    WinstonModule.forRoot({\n      transports,\n    }),\n
Run Code Online (Sandbox Code Playgroud)\n

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

\n

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

\n

小智 7

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

  format: winston.format.combine(
     winston.format.uncolorize()
     ...
Run Code Online (Sandbox Code Playgroud)

干杯