【问题标题】:npm winston set log level for basic logging instancenpm winston 为基本日志实例设置日志级别
【发布时间】:2015-04-21 15:15:51
【问题描述】:

在“简单模式”中将 winston 日志级别设置为“调试”没有很好的记录,因此我在下面展示了一个示例(并将很快提交 PR)。

答案是winston.level = 'debug'

我想在节点脚本中使用 winston 日志包,而不需要任何配置,只需调用winston.debugwinston.infowinston.error,然后将日志级别作为命令行参数传递. “简单模式”的文档不包括如何设置日志级别,所以我在下面展示了它。

代码:

var winston = require('winston');

winston.transports.Console.level = "debug";

winston.log("error", "error test 1");
winston.log("info", "info test 1");
winston.log("debug", "debug test 1");

winston.level = "debug";

winston.log("error", "error test 2");
winston.log("info", "info test 2");
winston.log("debug", "debug test 2");

将输出:

error: error test 1
info: info test 1
error: error test 2
info: info test 2
debug: debug test 2

希望对你有帮助

【问题讨论】:

标签: node.js winston


【解决方案1】:

答案是winston.level = 'debug'

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-03-10
    • 2014-01-22
    • 1970-01-01
    • 2023-03-23
    • 1970-01-01
    • 2012-05-04
    • 2017-10-01
    • 1970-01-01
    相关资源
    最近更新 更多