A majority of the Log4j 2.0 constants are structured by means of
"public final" fields initialized via system properties. While this
serves great for accessibility, IMHO, becomes an obstacle for tests.
For instance, I have needed two maven-surefire-plugin executions for
log4j2-logstash-layout: one with TLA enabled and another one with TLA
disabled. I have tried invoking System.setProperty() to influence
these constants for tests via both "static { }" blocks and
@BeforeClass methods, but neither kicks in earlier than the Log4j
constant class initialization itself. Is it just me that couldn't get
it working or this approach indeed hampers testing? If the latter, for
Log4j 3.0, I propose using injection to pass configuration state
rather than accessing it via globals.

Reply via email to