One option is the SequenceNumber
<https://github.com/apache/logging-log4j2/blob/76d78fe9a4adecebd9805d051a1606b2ac70ccd0/log4j-core/src/main/java/org/apache/logging/log4j/core/pattern/SequenceNumberPatternConverter.java>
pattern converter %sn in PatternLayout
<https://logging.apache.org/log4j/2.x/manual/layouts.html#PatternLayout>.
This uses a static counter, so if you need to keep separate track of
multiple appenders this may not be useful.
What you could do then is create a custom pattern converter plugin or
lookup plugin.

On Sun, Dec 11, 2016 at 8:40 PM, Guy Marom <marom....@gmail.com> wrote:

> Hello everyone,
> I want to count all the logging events into our metrics system
> (Prometheus). Our devs are using this to create alerts for Error/Fatal/Warn
> events.
>
> I gave up using filters because they catch all the events and not just the
> ones that are actually written to the logger.
>
> My current idea is to use a rewrite appender with my own rewrite policy
> which will just increment the relevant counter and not modify the event.
> The problem with this approach is again the filters, if an appender has a
> filter defined then I will count  events that end up discarded.
>
> Is there some post-logging hook I can use? An event maybe? Any help will
> be much appreciated...
> Thanks,
> Guy Marom
>

Reply via email to