在搜索了Sails.js文档,GitHub问题,谷歌小组以及SO之后,我仍然无法弄清楚我做错了什么......
我想使用Winston以3种不同的日志级别记录3种不同的传输:
在我的config/log.js
文件中,我有以下内容:
var Winston = require('winston');
var Loggly = require('winston-loggly');
var Sentry = require('winston-sentry');
module.exports.log = {
// Without this the log level is prefixed to messages twice
// for some reason...
prefixes: {},
// Without this, Winston Sails seems to only send "info"
// logs to Winston (Sails' default log level)...
level: 'verbose',
custom: new Winston.Logger({
transports: [
new Winston.transports.Sentry({
level: 'warn',
dsn: '{my account dsn}',
patchGlobal: true
}),
new Winston.transports.Loggly({
level: 'info',
subdomain: '{my subdomain}',
inoputToken: '{my input token}'
}),
new Winston.transports.Console({
level: 'verbose'
})
]
})
};
但是上面的设置有很多问题:
verbose
日志已发送到Loggly ... root
个错误,我认为这些错误来自patchGlobal
选项。被拒绝的蓝鸟承诺没有任何警告和“可能未被捕获的异常”错误。有人能指出我正确的方向吗?我做错了什么?
答案 0 :(得分:2)
好吧,看起来Winston根据数字级别写入日志。因此,错误消息将始终写入信息日志,但信息永远不会记录错误。
所以我认为最好将 config / bootstrap.js 中的不同实例分开:
sails.warnLog = new (winston.Logger)({
transports: [
new (winston.transports.Sentry)({
name: 'warn-Sentry',
dsn: '{my account dsn}',
patchGlobal: true
level: 'warn'
})
]});
sails.infLog = new (winston.Logger)({
transports: [
new (winston.transports.Loggly)({
name: 'info-Loggly',
subdomain: '{my subdomain}',
inputToken: '{my input token}'
level: 'info'
})
]});
sails.verbLog = new (winston.Logger)({
transports: [
new (winston.transports.Console)({
name: 'verb-console',
timestamp: true,
prettyPrint: true,
colorize: true,
level: 'verbose'
})
]});
然后你可以写日志:
sails.warnLog.warn('Warning');
sails.infLog.info('Information');
sails.verbLog.verbose('Verbose');
事实上,我不喜欢这种方式。这很丑陋=(