express-winston 中怎么设置按天(周)生成日志文件?
通过 express-winston 可以记录请求日志。但怎么设置按时间生成日志文件。一个文件不合理,时间长了,不方便。
node新手,熟悉后台开发的希望多多指教。当然更希望是实际开发中要求的。而不是一个demo实现。
// expressWinston.requestWhitelist.push('body');
// expressWinston.responseWhitelist.push('body');
app.use(expressWinston.logger({
transports: [
new winston.transports.Console({
json: true,
colorize: true
}),
new winston.transports.File({
filename: 'log/success.log'
})
],
requestWhitelist: ["body"], // Array of request properties to log. Overrides global requestWhitelist for this instance
responseWhitelist: ["body"], // Array of response properties to log. Overrides global responseWhitelist for this instance
meta: true, // optional: control whether you want to log the meta data about the request (default to true)
msg: "HTTP {{req.method}} {{req.url}}", // optional: customize the default logging message. E.g. "{{res.statusCode}} {{req.method}} {{res.responseTime}}ms {{req.url}}"
expressFormat: true, // Use the default Express/morgan request formatting. Enabling this will override any msg if true. Will only output colors with colorize set to true
colorize: true, // Color the text and status code, using the Express/morgan color palette (text: gray, status: default green, 3XX cyan, 4XX yellow, 5XX red).
ignoreRoute: function (req, res) { return false; } // optional: allows to skip some log messages based on request and/or response
}));
// 路由
routes(app);
// 错误请求的日志
app.use(expressWinston.errorLogger({
transports: [
new winston.transports.Console({
json: true,
colorize: true
}),
new winston.transports.File({
filename: 'log/error.log'
})
]
}));
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
winston-daily-rotate-file
问下,找到方法了吗,同问