Closed linhuanfengQ closed 6 months ago
Before answering your question, I have the impression that what you are after can be (and maybe should be?) done at the sink level. That is, assume your log sink is an Elasticsearch cluster. Why don't you count the calls there? If you can elaborate on your use case, I think we can help better.
Extending loggers is not the way you intercept Log4j. You can implement either a filter or an appender (that wraps your actual appender) and there you can extract statistics that suit your need.
You can check out FailoverAppender
docs and FailoverAppender.java
for inspiration.
Open KotlinLogger because I want to inherit it, rewrite the error method, and count the number of error calls. Of course, if there are other ways to meet my needs, I would be more than happy to ask for your advice