简体   繁体   English

使用 slf4j 和 kafka 进行日志记录

[英]Logging with slf4j and kafka

I have a kafka app that consumes from a topic and writes to another topic.我有一个 kafka 应用程序,它从一个主题消费并写入另一个主题。 Logging is done with slf4j .使用slf4j完成日志记录。 It logs info and error to separate files.它将信息和错误记录到单独的文件中。 My app has a problem and sometimes encounters INVALID_FETCH_SESSION_EPOCH error.我的应用程序出现问题,有时会遇到INVALID_FETCH_SESSION_EPOCH错误。

The problem is this error ends up in my info file and the app hangs forever and needs a restart.问题是这个错误最终出现在我的信息文件中,并且应用程序永远挂起并且需要重新启动。 One solution is to find the root of this invalid epoch problem that is irrelevant to my questions now.一种解决方案是找到这个与我现在的问题无关的无效时代问题的根源。

My problem is how can I check my logs for this error and restart the app automatically when it happens.我的问题是如何检查我的日志中是否存在此错误并在发生此错误时自动重新启动应用程序。 I implemented my own custom logger by extending Logger and ILoggerFactory but they still cannot inspect this error.我通过扩展 Logger 和 ILoggerFactory 实现了我自己的自定义记录器,但他们仍然无法检查此错误。 It seems Kafka uses a different Logger to write it.似乎 Kafka 使用不同的 Logger 来编写它。

I can't check log files too since they are created by a rolling policy and will be a lot of hassles to implement.我也无法检查日志文件,因为它们是由滚动策略创建的,实施起来会很麻烦。 Is there anyway whatever ends up in my info files be checked by my custom method, prior to writing?在写作之前,我的信息文件中是否有任何内容需要通过我的自定义方法进行检查?

I added a custom filter to my logs.我在我的日志中添加了一个自定义过滤器。 In this filter I inspect the message and whenever it contains INVALID_FETCH_SESSION_EPOCH I call a method that restarts my app.在这个过滤器中,我检查消息,每当它包含INVALID_FETCH_SESSION_EPOCH时,我都会调用一个方法来重新启动我的应用程序。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM