[ 
https://issues.apache.org/jira/browse/LOG4J2-1652?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Tom updated LOG4J2-1652:
------------------------
    Description: 
I am trying to reset log4j via the following code at runtime in order to write 
to new logfiles in newly specified directory. 

{code:title=|borderStyle=solid}
final LoggerContext context = (org.apache.logging.log4j.core.LoggerContext) 
LogManager.getContext(false);
Configurator.shutdown(context);

// Init and reset
Configurator.initialize("", logConfigFile);
context.setConfigLocation(file.toURI());
{code}

My xml file:

{code:xml|borderStyle=solid}
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="WARN">
  <Appenders>
    <Console name="Console" target="SYSTEM_OUT">
      <PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - 
%msg%n"/>
    </Console>
    <File name="InformationFile" fileName="${sys:log.dir}/information.log" 
filePattern="${sys:log.dir}/information-%i.log">
          <PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - 
%msg%n"/>                        
        </File>   
  </Appenders>   
  <Loggers>
    <Root level="debug">
      <AppenderRef ref="Console"/>
      <AppenderRef ref="InformationFile"/>
    </Root>
  </Loggers>
</Configuration>        
{code}

Unfortunately, this does not work correctly. After the first shutdown, new 
logging files are created but both files are written in parallel. After the 
second shutdown only the first two files are accesse and the new files stay 
empty.
        
                

  was:
I am trying to reset log4j via the following code at runtime in order to write 
to new logfiles in newly specified directory. 

{code:title=|borderStyle=solid}
final LoggerContext context = (org.apache.logging.log4j.core.LoggerContext) 
LogManager.getContext(false);
Configurator.shutdown(context);

// Init and reset
Configurator.initialize("", logConfigFile);
context.setConfigLocation(file.toURI());
{code}

Unfortunately, this only works once correctly. After the second shutdown, new 
logging files are created but the output is still written to the old files. 
        
                


> Shutdown only works correctly once
> ----------------------------------
>
>                 Key: LOG4J2-1652
>                 URL: https://issues.apache.org/jira/browse/LOG4J2-1652
>             Project: Log4j 2
>          Issue Type: Bug
>    Affects Versions: 2.6.2, 2.7
>         Environment: Java 8
>            Reporter: Tom
>
> I am trying to reset log4j via the following code at runtime in order to 
> write to new logfiles in newly specified directory. 
> {code:title=|borderStyle=solid}
> final LoggerContext context = (org.apache.logging.log4j.core.LoggerContext) 
> LogManager.getContext(false);
> Configurator.shutdown(context);
> // Init and reset
> Configurator.initialize("", logConfigFile);
> context.setConfigLocation(file.toURI());
> {code}
> My xml file:
> {code:xml|borderStyle=solid}
> <?xml version="1.0" encoding="UTF-8"?>
> <Configuration status="WARN">
>   <Appenders>
>     <Console name="Console" target="SYSTEM_OUT">
>       <PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - 
> %msg%n"/>
>     </Console>
>     <File name="InformationFile" fileName="${sys:log.dir}/information.log" 
> filePattern="${sys:log.dir}/information-%i.log">
>         <PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - 
> %msg%n"/>                        
>       </File>   
>   </Appenders>   
>   <Loggers>
>     <Root level="debug">
>       <AppenderRef ref="Console"/>
>       <AppenderRef ref="InformationFile"/>
>     </Root>
>   </Loggers>
> </Configuration>      
> {code}
> Unfortunately, this does not work correctly. After the first shutdown, new 
> logging files are created but both files are written in parallel. After the 
> second shutdown only the first two files are accesse and the new files stay 
> empty.
>       
>               



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

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

Reply via email to