[英]Multiple log paths in bunyan
I'm using Bunyan with Restify to create an access.log which will store information about requests such as the endpoint, status-code etc... However, I'd like to separate the errors from this file and store them in a separate log-file. 我将Bunyan与Restify结合使用来创建一个access.log,该文件将存储有关请求的信息,例如端点,状态码等。但是,我想将错误与该文件分开,并将它们存储在单独的文件中日志文件。
I've tried creating the second error logger by adding an additional stream to the Bunyan logger instance, however errors aren't being written to error log-file. 我尝试通过向Bunyan记录器实例添加附加流来创建第二个错误记录器,但是错误并未写入错误日志文件中。 Any ideas why that is?
有什么想法吗?
var log = new Logger({
name: 'logga',
streams: [
{
stream: process.stdout,
level: 'debug'
},
{
path: './logs/access.log',
level: 'trace'
},
{
path: './logs/error.log',
level: 'error'
}
],
serializers: Logger.stdSerializers
});
server.on('uncaughtException', function (request, response, route, error) {
log.error(error);
});
You can remove serializers: Logger.stdSerializers
. 您可以删除
serializers: Logger.stdSerializers
。 That should fix it. 那应该解决它。
If the only log.error(error);
如果只有
log.error(error);
call is in your uncaughtException
handler, then most probably the error stream isn't being flushed before your process exits due to the uncaught exception. 调用在您的
uncaughtException
处理程序中,那么很可能由于未捕获的异常而在进程退出之前不会清除错误流。 You can try logging an error somewhere else to confirm that. 您可以尝试在其他地方记录错误以确认这一点。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.