Hessam
Hessam

Reputation: 1415

Logging with slf4j and kafka

I have a kafka app that consumes from a topic and writes to another topic. Logging is done with slf4j. It logs info and error to separate files. My app has a problem and sometimes encounters INVALID_FETCH_SESSION_EPOCH error.

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. It seems Kafka uses a different Logger to write it.

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?

Upvotes: 2

Views: 693

Answers (1)

Hessam
Hessam

Reputation: 1415

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.

Upvotes: 1

Related Questions