"Sets the log level to null” - which log level? The root, a particular logger, 
or a Threshold Filter on a particular appender? FWIW, in Log4j 1 setting the 
log level to null on a Logger just means it will inherit from its parent. That 
is not necessarily the case in Log4j 2.

“Then loads the property file” - what property file? The log4j 2 configuration 
file?  Why would you set the log sell to null before reloaded the 
configuration? 

“Without losing any appenders created with Java” - How are the appenders 
created with Java and why are they created with Java? You could use a composite 
configuration that adds your the “standard” configuration to what a user 
provides or you could extend XMLConfiguratoin with your own extra configuration.

In short, you still haven’t described what you want the resultant behavior to 
be. You are still describing “How?” instead of “What?”.  In other words - 
something like - “We want to require that a specific logger is always logged at 
error and those logs are always routed to a file named xxxx, regardless of what 
other things the user might configure”. 

Ralph

> On Dec 17, 2017, at 11:22 AM, Paladox <thomasmulhall...@yahoo.com.INVALID> 
> wrote:
> 
> Im trying to migrate gerrit from log4j1 to log4j2.
> With this we have a ssh command that resets log levels (ie sets the log level 
> to null then loads the Property file without restarting from fresh and 
> loosing any appenders that were created with java).
>    On Sunday, 17 December 2017, 17:56:42 GMT, Ralph Goers 
> <ralph.go...@dslextreme.com> wrote:  
> 
> 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



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

Reply via email to