我正在尝试在 Winston 中使用多种传输方式。这是工作......排序。我为应用程序的审核日志设置了传输,自定义级别为“审核”,传输为“信息”。
var winston_mongo_options = {
level: 'audit', // level that should be logged
safe: true, //makes sure writes happen before firing log event
db: config.db.db, // db in which to write logs
host: config.db.host,
port: config.db.port,
collection: config.db.audit_collection // collection we want logging to occur
};
if (config.db.user) {
winston_mongo_options.username = config.db.user;
winston_mongo_options.password = config.db.pass;
}
var custom_levels = winston.config.syslog.levels;
custom_levels.audit = 8;
var logger = new (winston.Logger)({
levels: custom_levels,
transports : [
new (winston.transports.MongoDB)(winston_mongo_options),
new (winston.transports.File)({
level: 'info',
silent: false,
colorize: true,
timestamp: true,
filename: config.logs.debug,
maxsize: 500000,
maxFiles: 5,
json: true
})
],
exceptionHandlers: [
new (winston.transports.File)({
silent: false,
colorize: false,
timestamp: true,
filename: config.logs.exception,
maxsize: 500000,
maxFiles: 5,
json: true
})
]
});
module.exports.logger = logger;
显然,我需要这个文件,我想在哪里/什么时候做任何日志记录。当想要将某些信息单独发送到日志时,就会出现问题。
logger.audit('Server Started - to DB');
logger.info('Server Started - to info');
这两行应该写入单独的日志。第一行被正确写入数据库和信息日志文件。我究竟做错了什么?