logging-log4j-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Ralph Goers <ralph.go...@dslextreme.com>
Subject Re: Programmatically Modifying the Current Configuration after Initialization
Date Fri, 09 Feb 2018 00:26:29 GMT
If you want to replace the existing configuration you should be able to do:

Configurator.initialize(“MyApp”, “app-log4j2.xml”);

This will look for a file named app-log4j2.xml on the class path.

Ralph

> On Feb 8, 2018, at 1:28 PM, Mike Kienenberger <mkienenb@gmail.com> wrote:
> 
> As others have reported in years past, the examples in the docs for
> 
> Programmatically Modifying the Current Configuration after Initialization
> 
> are out of date.  They don't compile.  They don't work (affect the
> existing logging) even if you do fix the errors.
> 
> Here's my situation:
> 
> I am working in an environment with EVIL.JAR which includes a log4j2.xml file.
> I can't change the jar.  I can't specific a System Property to override it.
> 
> My code gets called as a loaded module long after the logging system
> is initialized.
> 
> I want logging in my own code to go to a different location, and
> preferably I'd like to read the configuration in from a log4j2.xml
> file so that anyone who uses my module isn't victim to the same evil
> hardcoded-logging practices of EVIL.JAR.
> 
> Creating an XMLConfiguration and initializing it lets me read the xml
> file easily enough.   Looping through the data gets me the Appenders,
> Filters and Loggers.   But I still can't use them to modify the
> existing configuration.
> 
> Another person took the approach of using JUL instead.  I hate JUL and
> I'd really rather not have to go down that route.
> 
> Thanks in advance.
> -Mike
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
> For additional commands, e-mail: log4j-user-help@logging.apache.org
> 
> 



---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org


Mime
View raw message