apache / logging-log4j-kotlin

A Kotlin-friendly interface to log against the Log4j API
https://logging.apache.org/log4j/kotlin
Apache License 2.0
45 stars 11 forks source link

Open KotlinLogger #57

Closed linhuanfengQ closed 6 months ago

linhuanfengQ commented 6 months ago

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

vy commented 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.