Oh, I interpreted that backwards! Then the best layer to insert this logic
at might be as an appender wrapper of some sort like he mentioned already.

On 11 December 2016 at 16:05, Remko Popma <remko.po...@gmail.com> wrote:

> Matt,
>
> I think Guy wants to count at the Appender level after all filtering is
> done.
>
> Sent from my iPhone
>
> On 12 Dec 2016, at 3:00, Matt Sicker <boa...@gmail.com> wrote:
>
> Do you mean something similar to this?
> https://docs.oracle.com/javase/8/docs/api/java/util/
> logging/LogRecord.html#getSequenceNumber--
>
> Although I think that has the same limitation as the number won't increase
> if the log message is filtered before being appended (or in the JUL
> vocabulary, the log record may be filtered before being handled).
>
> You could generate some Logger wrappers using the tool <
> https://logging.apache.org/log4j/2.x/manual/customloglevels.html#CodeGen>
> and add in an AtomicLong. Do note that if you're trying to count filtered
> messages as well, you're going to lose the benefit of the no-ops when a
> message is filtered. Also, this still wouldn't work if someone uses the
> pattern:
>
> if (log.isDebugEnabled()) {
>   log.debug(...);
> }
>
> On 11 December 2016 at 07:08, Guy Marom <marom....@gmail.com> wrote:
>
>> Hello again,
>>
>> Well, I think that both these options are not good for me.
>> First I DO want to keep a separate track for each logger so the sequence
>> number is no good.
>>
>> Second, using the a custom pattern or a lookup plugin both seem too
>> intrusive to me. What if an appender already has a pattern or a lookup
>> defined?.
>>
>> Unless someone comes up with a better I think I'll stick with my rewrite
>> appender and just notify the user they cannot define a filter on the
>> appender if they want the metrics to reflect reality.
>>
>> Thanks a lot for the help,
>>
>> Guy
>>
>> On Sun, Dec 11, 2016 at 2:11 PM, Guy Marom <marom....@gmail.com> wrote:
>>
>>> Thanks, I'll take a look at this suggestion!
>>>
>>> On Sun, Dec 11, 2016 at 1:56 PM, Remko Popma <remko.po...@gmail.com>
>>> wrote:
>>>
>>>> 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
>>>>>
>>>>
>>>>
>>>
>>
>
>
> --
> Matt Sicker <boa...@gmail.com>
>
>


-- 
Matt Sicker <boa...@gmail.com>

Reply via email to