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');
これらの 2 行は、別々のログに書き込まれます。最初の行は、データベースと情報ログ ファイルに適切に書き込まれます。私は何を間違っていますか?