Uploaded image for project: 'Log4j 2'
  1. Log4j 2
  2. LOG4J2-2875

StreamClosed IOException after first time based rolling

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 2.13.3
    • Fix Version/s: 2.14.0
    • Component/s: None
    • Labels:
      None

      Description

      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:

      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);
         }
       }
      }
      

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                rgoers Ralph Goers
                Reporter:
                asbachb Benjamin Asbach
              • Votes:
                0 Vote for this issue
                Watchers:
                3 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: