首页 > 解决方案 > 使用 NodeJs 进行高级日志记录:在 winston@3.0.0 中删除了 { emitErrs }

问题描述

我创建了这个函数来登录到一个详细级别设置为 info 的文件,每个文件最多 5 个文件和 5 MB,并且在终端中有一个完整的完整日志(详细级别调试),但不同的级别应该使用不同的颜色。

private initialize(): void {

        var winston = require('winston');
        winston.emitErrs = true;

        var logger = new winston.Logger({
            transports: [
                new winston.transports.File({
                    level: 'info',
                    filename: './logs/all-logs.log',
                    handleExceptions: true,
                    json: true,
                    maxsize: 5242880, //5MB
                    maxFiles: 5,
                    colorize: false
                }),
                new winston.transports.Console({
                    level: 'debug',
                    handleExceptions: true,
                    json: false,
                    colorize: true
                })
            ],
            exitOnError: false
        });

        module.exports = logger;
        module.exports.stream = {
            write: function(message : any, encoding : any){
                logger.info(message);
            }
        };

    }

但是启动应用程序时出现此错误。

发生意外错误错误:在 winston@3.0.0 中删除了 { emitErrs }。

标签: node.jslogging

解决方案


emitErrs选项在 3.0.0 中被删除。只需将其从您的代码中删除即可。这一行具体:

winston.emitErrs = true;

看到这个关于 GH 的评论


推荐阅读