log-captor icon indicating copy to clipboard operation
log-captor copied to clipboard

Allow to retrieve logs for custom log levels

Open danipalli opened this issue 1 year ago • 1 comments

** Feature description ** If I configured my e.g. Log4jLogger with custom log levels (e.g. LogLevel.forName("CUSTOM_LEVEL", 401)), the I would want to be able to call a method like LogCaptor#getLogs(CUSTOM_LEVEL); or LogCaptor#getLogs(CUSTOM_LEVEL.getName()); to get all the relevant logs for my custom LogLevel.

** Possible solution ** I haven't tried it, but changing the visibility of the LogCaptor#getLogs(Level level); method from private to public might already do the trick.

** Alternative solution ** An alternative currently is to call getLogs() and then filter the logs by myself. That's not really a problem, but the feature is easy to implement and quite useful, so why not implement it.

danipalli avatar Jul 28 '22 06:07 danipalli

Hi @danipalli thank you for your suggestion. It is indeed possible with log4j logger to have custom log levels. However these are being unfortunately ignored by the underlying mapper. This mapper forwards logs from log4j to SLF4J, which is done by org.apache.logging.log4j:log4j-to-slf4j. I have done a test locally to log something with a custom log level and the mapper maps it always to debug level. So i think it is not possible to have this feature.

But if you want you can give it a try, maybe you can find a way :)

Hakky54 avatar Aug 05 '22 10:08 Hakky54

Hi @Hakky54, as it is not as easy to implement as I thought, leaving it as it is, is the better option I think. Especially because you can get the functionality that I wanted with the alternative solution that I mentioned above.

But thank you for taking a look at it :)

danipalli avatar Aug 20 '22 11:08 danipalli