SmtpAppender in log4j2, plus how to reconfigure everything

Christopher Schultz <[email protected]> Fri, 30 May 2025 14:23:39 -0400
Newsgroups gmane.comp.jakarta.log4j.user
Message-ID <[email protected]>
All,

A few years ago, I posted to this list with the subject "[log4j 1.x] 
Batch-sending with SMTPAppender". I can't seem to find it on lists.a.o 
for a reference. Sorry.

Anyhow, I'm really trying to make the switch to log4j2 but there are 
just so many things that do not work.

For my purposes, I need to be able to:

1. Attach custom headers to SMTP messages.

I did this by creating a custom subclass[1] of SMTPAppender that 
overrides activateOptions and sets whatever headers I need on the SMTP 
message.

In log4j2, SmtpAppender is final, so this is no longer possible.

Are there any suggestions for how to add custom headers to messages sent 
via SmtpAppender?

2. Don't send log messages as individual SMTP messages, send all at once.

I did this by creating a custom[2] TriggeringEventEvaluator that simply 
delays triggering until it gets to some high threshold.

There doesn't seem to be anything at all like that in log4j2.

Are there any suggestions for how to get multiple log events per SMTP 
message?

3. Re-configure the logging system to enable TRACE logging (or really 
anything kinda like this).

The idea is that there is an on-disk file with the typical configuration 
(e.g. production-style low-message-output config) but then I'd like to 
pick out a specific logger or appender, change its threshold, and have 
that configuration become effective across the whole logging system, at 
runtime, without re-starting the JVM or anything like that.

I used to do that by using PropertyConfigurator.configure(Properties) 
but all of that is gone, now, in log4j2.

Is there a way to get the currently-effective configuration from log4j 
at runtime? Once I've got that configuration, if I modify it, how can I 
re-initialize everything so that altered configuration becomes active?

Thanks,
-chris

[1] 
https://github.com/ChristopherSchultz/log4j-1.x/blob/main/java/org/apache/log4j/extras/ExtendedSMTPAppender.java
[2] 
https://github.com/ChristopherSchultz/log4j-1.x/blob/main/java/org/apache/log4j/extras/DelayedTriggeringEventEvaluator.java