winston と winston-mongodb をセットアップして、エクスプレス アプリのログを記録します。問題は、localhost:3000/apidocs や localhost:3000/index などのルート ディレクトリにあるエンドポイントのログのみを記録していることですが、localhost:3000/api/v1/customers に REST アプリ全体があり、そのようなアドレスに対してリクエストが行われた場合、ログは表示されません。次のコードは、エクスプレス ウィンストンをセットアップする方法を示しています。
winston.add(MongoDB, {db:'logs'});
app.use(expressWinston.logger({
transports: [
new winston.transports.Console({
json: true,
colorize: true
}),
new (winston.transports.MongoDB)(
{
db : 'logs',
}
)
]
}));
app.use(app.router);
app.use(expressWinston.errorLogger({
transports: [
new winston.transports.Console({
json: true,
colorize: true
}),
new (winston.transports.MongoDB)(
{
db : 'logs',
}
)
]
}));
どんな助けでも本当に感謝しています。