You might have to use an XML configuration file to get that to work in Log4j 1: See org.apache.log4j.net.SMTPAppenderTest.testTrigger()
Gary On Wed, Nov 16, 2016 at 9:11 AM, Christopher Schultz < ch...@christopherschultz.net> wrote: > Ralph, > > 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 what you mean by “each log message seems to generate its > > own separate email message”. The SMTP appender accumulates log events > > in a buffer until a triggering event occurs (usually an error event) > > and then all the buffered events are sent in an email. > > This is not what I'm seeing. I'm seeing e.g. 10 ERROR messages logged in > the span of about a minute to the main log file (e.g. my-process.log on > the disk) and then 10 separate email messages with one log line per > message in them. > > I have an example from 09:25 US-Eastern this morning: I got 7 separate > email messages. The first message has this content (timestamps are UTC): > > 2016-11-16 14:25:52,893 [main] ERROR [...logger and message content...] > > The last one has this content: > > 2016-11-16 14:27:13,569 [main] ERROR [...logger and message content...] > > So in the space of about 90 seconds, log4j sent 7 separate email > messages, and each email message contained a single log line. > > I happen to be using log4j 1.2.17 which was the final release of log4j 1.x. > > When you say "an error event" will trigger an email to be sent... do you > mean a log.error() call? If so, perhaps the problem is that my threshold > has been set to ERROR so I'm only reacting to ERROR events. If I were > logging at the TRACE level, would I get a whole bunch of TRACE and a > single ERROR in each email message? > > Looking at the javadoc, it seems like that might be the case: > > " > The default constructor will instantiate the appender with a > TriggeringEventEvaluator that will trigger on events with level ERROR or > higher. > " > > I'm using a .properties file to configure log4j. How can I configure a > TriggeringEventEvaluator to, saw, only trigger on e.g. FATAL log events? > > > This happens each time a triggering event occurs. I see the logic for > > sendOnClose and expect what you are doing should work, but I haven’t > > worked with the Log4j 1 code in years so I can’t say for sure. > > Thanks, > -chris > > -- E-Mail: garydgreg...@gmail.com | ggreg...@apache.org Java Persistence with Hibernate, Second Edition <https://www.amazon.com/gp/product/1617290459/ref=as_li_tl?ie=UTF8&camp=1789&creative=9325&creativeASIN=1617290459&linkCode=as2&tag=garygregory-20&linkId=cadb800f39946ec62ea2b1af9fe6a2b8> <http:////ir-na.amazon-adsystem.com/e/ir?t=garygregory-20&l=am2&o=1&a=1617290459> JUnit in Action, Second Edition <https://www.amazon.com/gp/product/1935182021/ref=as_li_tl?ie=UTF8&camp=1789&creative=9325&creativeASIN=1935182021&linkCode=as2&tag=garygregory-20&linkId=31ecd1f6b6d1eaf8886ac902a24de418%22> <http:////ir-na.amazon-adsystem.com/e/ir?t=garygregory-20&l=am2&o=1&a=1935182021> Spring Batch in Action <https://www.amazon.com/gp/product/1935182951/ref=as_li_tl?ie=UTF8&camp=1789&creative=9325&creativeASIN=1935182951&linkCode=%7B%7BlinkCode%7D%7D&tag=garygregory-20&linkId=%7B%7Blink_id%7D%7D%22%3ESpring+Batch+in+Action> <http:////ir-na.amazon-adsystem.com/e/ir?t=garygregory-20&l=am2&o=1&a=1935182951> Blog: http://garygregory.wordpress.com Home: http://garygregory.com/ Tweet! http://twitter.com/GaryGregory