Why are you trying to do this? What problem are you trying to solve? Simply trying to port code from Log4j 1 to Log4j 2 without evaluating what the best way is to achieve the desired results is not an approach I recommend.
Ralph > On Dec 16, 2017, at 1:18 PM, Paladox <thomasmulhall...@yahoo.com.INVALID> > wrote: > > Would like to add more to this question. > Im wondering is it possible to also reset log levels? > In log4j1.x we did > private static void reset() throws MalformedURLException { for > (Enumeration<Logger> logger = LogManager.getCurrentLoggers(); > logger.hasMoreElements(); ) { logger.nextElement().setLevel(null); } > String path = System.getProperty(JAVA_OPTIONS_LOG_CONFIG); if > (Strings.isNullOrEmpty(path)) { > PropertyConfigurator.configure(Loader.getResource(LOG_CONFIGURATION)); } > else { PropertyConfigurator.configure(new URL(path)); } } > in log4j2 i carn't find any good replacements. Setting setLevel results in > null pointer same would be for setAllLevels. (Works in log4j1). > Then when i try to reload the properties file it just resets everything then > loads the file. Thus if you used some java code it would be lost and you > would have to restart your java application to get the appenders or anything > added with java code. > In log4j1 you need PropertyConfigurator.configure which re added the log > levels that were from the file without resetting anything. > On Friday, 15 December 2017, 16:50:28 GMT, Paladox > <thomasmulhall...@yahoo.com.INVALID> wrote: > > Hi, im wondering if i could have some help with migrating from log4j1 to > log4j2 please? > Im trying to update gerrit to log4j2 but am stuck on some things. [1] > 1. How do i migrate from > PropertyConfigurator.configure(Loader.getResource(LOG_CONFIGURATION)); to > something log4j2 compatible please? > Im trying to migrate all the way without trying to use log4j1 compatible api > log4j2. (Though im still pulling it in i am trying not to use it). > I found doing something like > String path = System.getProperty(JAVA_OPTIONS_LOG_CONFIG); if > (Strings.isNullOrEmpty(path)) { ConfigurationSource source = > ConfigurationSource.fromResource(LOG_CONFIGURATION, null); > Configurator.initialize(null, source); } else { URL in = new > URL(path); Configurator.initialize((String) null, null, in.toURI()); } > could work but then it wont reload the configuation without restarting the > configuation as new (ie gets rid of everything). which .reconfigure() does. > Im trying to reset log levels to null so that we can reload the configuation > but reconfigure gets rid of everything thus causing problems if you used java > to add appenders or anything else. see [2] > Also how would i migrate from using removeAllAppenders to log4j2 compatible > code please? > [1] https://gerrit-review.googlesource.com/#/c/gerrit/+/142811/ > [2] > https://gerrit-review.googlesource.com/#/c/gerrit/+/142811/46/java/com/google/gerrit/sshd/commands/SetLoggingLevelCommand.java > --------------------------------------------------------------------- To unsubscribe, e-mail: log4j-user-unsubscr...@logging.apache.org For additional commands, e-mail: log4j-user-h...@logging.apache.org