我试图让 Winston 漂亮地打印到控制台,所以我将它保存在一个文件中并使用 node 运行它:
var winston = require('winston');
winston.cli();
winston.data({
a: "test",
of: "many",
properties: {
like: "this"
}
});
winston.data('data', {
a: "test",
of: "many",
properties: {
like: "this"
}
});
终端返回以下(不完全漂亮)消息:
data: a=test, of=many, like=this
data: data a=test, of=many, like=this
我正在按照 Winston Readme 上的说明进行操作(“在 CLI 工具中使用 winston”)。我误读了什么吗?某处缺少设置?
最佳答案
我找到了答案(文档不正确)。如果您使用构造函数并手动添加传输,则可以为 winston 和单个传输设置选项。某些选项需要直接添加到 winston 中,而其他选项需要添加到传输中。
例如:
var winston = require('winston');
var logger = new (winston.Logger)({
levels: {
trace: 0,
input: 1,
verbose: 2,
prompt: 3,
debug: 4,
info: 5,
data: 6,
help: 7,
warn: 8,
error: 9
},
colors: {
trace: 'magenta',
input: 'grey',
verbose: 'cyan',
prompt: 'grey',
debug: 'blue',
info: 'green',
data: 'grey',
help: 'cyan',
warn: 'yellow',
error: 'red'
}
});
logger.add(winston.transports.Console, {
level: 'trace',
prettyPrint: true,
colorize: true,
silent: false,
timestamp: false
});
logger.add(winston.transports.File, {
prettyPrint: false,
level: 'info',
silent: false,
colorize: true,
timestamp: true,
filename: './nKindler.log',
maxsize: 40000,
maxFiles: 10,
json: false
});
关于node.js - winston 不能漂亮地打印到控制台,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17963406/