First, I have to say that Log4j 1 reached end-of-life over a year ago. We recommend you upgrade to Log4j 2.
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 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. Ralph > On Nov 16, 2016, at 7:24 AM, Christopher Schultz > <schultz.christop...@gmail.com> wrote: > > All, > > Apologies if this has been posted before.. I checked the archives but > it's hard to search for such terms... lots of stuff comes up. > > I have an SMTPAppender configured and it's working (mostly) as expected. > The only problem is that each log message seems to generate its own > separate email message. > > My use-case is a periodic job where I'd like to send any errors to an > email box. Two configuration settings for the SMTPAppender led me to > believe that the SMTPAppender might batch emails: > > 1. BufferSize > 2. SendOnClose > > The javadoc specifically mentions that the BufferSize will affect the > number of logging events delivered "in this email" which I assumed meant > "each email message". > > My relevant configuration: > > log4j.appender.CLIENT.bufferSize=500 > log4j.appender.CLIENT.sendOnClose=true > > Usually, we get something like 0 - 12 errors per run of this periodic > job, so I wouldn't expect to get anywhere near the 500 limit. Ideally, > all of those log messages would be batched together and sent when the > logger shuts down. At the end of the program, I do one of these: > > finally > { > org.apache.log4j.LogManager.shutdown(); > } > > That ought to trigger the SendOnClose behavior and flush anything that > hasn't already been sent. > > Am I missing something in my configuration that is required to send > these messages in batches? I'd prefer not to write the logs to a > separate file and then use a secondary process to email that log file to > the intended recipient. > > Thanks, > -chris > --------------------------------------------------------------------- To unsubscribe, e-mail: log4j-user-unsubscr...@logging.apache.org For additional commands, e-mail: log4j-user-h...@logging.apache.org