logging-log4j-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Christopher Schultz <ch...@christopherschultz.net>
Subject Re: [log4j 1.x] Batch-sending with SMTPAppender
Date Thu, 17 Nov 2016 15:28:54 GMT
All,

On 11/17/16 10:20 AM, Christopher Schultz wrote:
> All,
> 
> On 11/16/16 5:33 PM, Christopher Schultz wrote:
>> Scott,
>>
>> On 11/16/16 2:09 PM, Scott Harrington wrote:
>>>>> On 11/16/16 9:49 AM, Ralph Goers wrote:
>>>>>> First, I have to say that Log4j 1 reached end-of-life over a year
>>>>>> ago. We recommend you upgrade to Log4j 2.
>>>>>
>>>>> Fair enough. I'm not quite there, yet. I suspect that log4j 2 will have
>>>>> the same issue, though.
>>>>
>>>> I don’t know how to configure a TriggeringEventEvaluator in Log4j 1
>>>> but I’d bet google does ;-)
>>>
>>> Chris: I have a ThrottledSMTPApppender subclass that I used for years
>>> under Log4j 1.x, it's very small but was somewhat tricky; it starts a
>>> "flusher" thread and attaches a shutdown hook to drain before exit.
>>> There is a TriggeringEventEvaluator that always returns false. There is
>>> a configureable "initialDelay" (default 10 seconds) and
>>> "messageInterval" (default 60 seconds).
>>
>> That sounds cool, but maybe overkill if I can get the
>> TriggeringEventEvaluator working with the stock log4j distro.
>>
>> (It looks like I'll need to write my own NeverTriggerEventEvaluator to
>> do that. It looks trivial so I'll try that first.)
> 
> So, I implemented an event trigger class in my driver class like this:
> 
> package com.my;
> public class Driver
> {
>     [...]
>     public static class NeverTriggeringEventEvaluator
>         implements TriggeringEventEvaluator
>     {
>         @Override
>         public boolean isTriggeringEvent(LoggingEvent arg0) {
>             return false;
>         }
>     }
> }
> 
> I enabled it in my configuration file like this:
> 
> log4j.appender.CLIENT.evaluatorClass=com.my.Driver.NeverTriggeringEventEvaluator
> 
> When log4j initializes itself it emits this error on stdout:
> 
> log4j:ERROR Could not instantiate class
> [com.my.Driver.NeverTriggeringEventEvaluator].
> java.lang.ClassNotFoundException:
> com.chadis.unity.CHADISProUnityBridge.NeverTriggeringEventEvaluator
> 	at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
>         [...]
> 
> I'm not using any special ClassLoader acrobatics or anything like that.
> I copy/pasted the name of the fully-qualified class name from Eclipse so
> it's not a typo.
> 
> If I run "javap" with that class name and the effective CLASSPATH of the
> process when it runs, I get this output:
> 
> $ javap -classpath build/classes com.my.Driver.NeverTriggeringEventEvaluator
> 
> Compiled from "Driver.java"
> public class com.my.Driver$NeverTriggeringEventEvaluator implements
> org.apache.log4j.spi.TriggeringEventEvaluator {
>   public com.my.Driver$NeverTriggeringEventEvaluator();
>   public boolean isTriggeringEvent(org.apache.log4j.spi.LoggingEvent);
> }
> 
> Any ideas?
> 
> Do I need to use com.my.Driver$NeverTriggeringEventEvaluator instead?
> (Obviously, I'm trying that without waiting for an answer.)

That was it: the NeverTriggeringEventEvaluator is working as expected
when using the '$' embedded in the class name.

Thanks,
-chris


Mime
View raw message