【发布时间】:2015-04-21 15:15:51
【问题描述】:
在“简单模式”中将 winston 日志级别设置为“调试”没有很好的记录,因此我在下面展示了一个示例(并将很快提交 PR)。
答案是winston.level = 'debug'
我想在节点脚本中使用 winston 日志包,而不需要任何配置,只需调用winston.debug、winston.info、winston.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
希望对你有帮助
【问题讨论】: