loggingcachinglog4j2appender

Is it possible in log4j2 to cache and get log messages so it can be used e.g. for alarm mails?


I'm currently migrating from log4j 1 to 2.

In log4j 1 I have my own Appender which therefore can cache the last 10 log messages in the java code.

Is something like this possible in log4j 2 where the appender or something similar is caching x messages? Is there a feature for log4j 2 that provides this functionality with just configuration or where can I code this with log4j 2?

Thanks in advance


Solution

  • I solved this issue by creating my own »Filter« saving messages when they come in. It's of course not actually filtering something, but the messages can be saved when they are coming by.

    See https://logging.apache.org/log4j/log4j-2.0/manual/extending.html#Filters and https://logging.apache.org/log4j/log4j-2.0/manual/plugins.html for more information