【问题标题】:winston - TypeError: winston.createLogger is not a constructorwinston - TypeError:winston.createLogger 不是构造函数
【发布时间】:2019-06-16 17:22:11
【问题描述】:

winston.createLogger();显然不是构造函数。为什么会这样?

我看到有些人尝试回滚到 winston@3.0.0,但这对我不起作用。我正在使用最新版本的温斯顿。这是一些logger.js:

const winston = require('winston');

const level = process.env.LOG_LEVEL || 'debug';


let logger = new winston.createLogger({
    transports: [
        new winston.transports.Console({
            level: level,
            timestamp: function() {
                return (new Date()).toISOString();
            }
        })
    ]
});

module.exports = logger;

我希望它创建记录器,但它抛出一个 TypeError 告诉我 createLogger 不是构造函数!

【问题讨论】:

    标签: node.js logging npm winston


    【解决方案1】:

    它只是winston.createLogger 而不是new winston.createLogger。不需要new 关键字。

    【讨论】:

      【解决方案2】:

      请勿使用new winston.Logger(opts) - 已将其删除以提高性能。请改用winston.createLogger(opts)。

      查看this 以供参考

      【讨论】:

        猜你喜欢
        • 2019-05-30
        • 1970-01-01
        • 2018-12-07
        • 2013-12-25
        • 2021-01-11
        • 2015-12-04
        • 2018-11-29
        • 2016-12-04
        • 2020-12-27
        相关资源
        最近更新 更多