npm winston设置基本日志记录实例的日志级别

时间:2015-02-20 02:10:59

标签: node.js winston

在'简易模式'中将winston日志级别设置为'debug'没有详细记录,因此我在下面显示了一个示例(并将很快提交PR)。

答案是winston.level = 'debug'

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

代码:

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

希望这有帮助

1 个答案:

答案 0 :(得分:0)

答案是winston.level = 'debug'