【问题标题】:nestjs winston log file is written with colors encodingnestjs winston 日志文件是用颜色编码编写的
【发布时间】:2021-04-04 12:27:54
【问题描述】:

我面临与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",

【问题讨论】:

    标签: nestjs winston express-winston


    【解决方案1】:

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

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

    干杯

    【讨论】:

    • 非常感谢@MrARC,这回答并解决了我的问题。
    猜你喜欢
    • 2020-06-27
    • 1970-01-01
    • 2019-05-20
    • 1970-01-01
    • 2021-04-26
    • 2018-03-21
    • 2011-11-16
    • 2018-03-07
    • 2015-06-20
    相关资源
    最近更新 更多