You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@logging.apache.org by "Benjamin Asbach (Jira)" <ji...@apache.org> on 2020/06/18 15:36:00 UTC

[jira] [Created] (LOG4J2-2875) StreamClosed IOException after first time based rolling

Benjamin Asbach created LOG4J2-2875:
---------------------------------------

             Summary: StreamClosed IOException after first time based rolling
                 Key: LOG4J2-2875
                 URL: https://issues.apache.org/jira/browse/LOG4J2-2875
             Project: Log4j 2
          Issue Type: Bug
    Affects Versions: 2.13.3
            Reporter: Benjamin Asbach


An IOException is occuring when the first time based rolling was done. It seems that the new folder is not created and because of that the log cannot be written.

Example:
{code:java}
import java.util.Properties;
import org.apache.logging.log4j.core.Logger;
import org.apache.logging.log4j.core.LoggerContext;
import org.apache.logging.log4j.core.config.properties.PropertiesConfiguration;
import org.apache.logging.log4j.core.config.properties.PropertiesConfigurationBuilder;
import org.junit.jupiter.api.Test;

public class RollingTest {

 @Test
 public void streamClosedError() throws Exception {
   Properties log4j2Properties = new Properties();
   log4j2Properties.put("appender.localmsglog.type", "RollingFile");
   log4j2Properties.put("appender.localmsglog.name", "localmsglog");
   log4j2Properties.put("appender.localmsglog.filePattern", "C:/dev/tmp/log/%d{yyyy_MM_dd-mm}/messages-$${date:yyyy_MM_dd_HH_mm_ss}.log");
   log4j2Properties.put("appender.localmsglog.policies.type", "Policies");
   log4j2Properties.put("appender.localmsglog.policies.1.type", "TimeBasedTriggeringPolicy");

   log4j2Properties.put("rootLogger.level", "info");
   log4j2Properties.put("rootLogger.appenderRef.1.ref", "localmsglog");

   PropertiesConfiguration config = new PropertiesConfigurationBuilder()
           .setRootProperties(log4j2Properties)
           .build();

   org.apache.logging.log4j.core.config.Configurator.reconfigure(config);

   LoggerContext context = LoggerContext.getContext(false);
   Logger log = context.getRootLogger();
   while(true) {
     log.info("AAA");
     Thread.sleep(15000);
   }
 }
}
{code}




--
This message was sent by Atlassian Jira
(v8.3.4#803005)