Uploaded image for project: 'logback'
  1. logback
  2. LOGBACK-1066

cannot close files with SiftingAppender

    XMLWordPrintable

Details

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: Major Major
    • None
    • 1.1.3
    • logback-classic
    • Windows 7

    Description

      I'm using SiftingAppender in my application to log processes in different files. Here is my appender:

      <property scope="context" name="PROCESS_LOG_HOME" value="processLogs" />
        
      	<appender name="PROCESS_LOGGER" class="ch.qos.logback.classic.sift.SiftingAppender">
       
      		<timeout>1 minute</timeout>
      		
      		<discriminator>
      			<key>processLogName</key>
      			<defaultValue>defaultLog</defaultValue>
      		</discriminator>
       
      		<sift>
       
      		  <appender name="PROCESS-LOGGER-${processLogName}" class="ch.qos.logback.core.rolling.RollingFileAppender">
      				<file>${PROCESS_LOG_HOME}/${processLogName}.log</file>
      	 
      				<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
      					<Pattern>
      						%d{yyyy-MM-dd HH:mm:ss} %-5level - %msg%n
      					</Pattern>
      				</encoder>
      	 
      				<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
      					<FileNamePattern>${PROCESS_LOG_HOME}/${processLogName}%d.log</FileNamePattern>
      					<!-- keep 7 days worth of history -->
      					<MaxHistory>7</MaxHistory>
      				</rollingPolicy>
      	 
      			</appender>
       
      		</sift>
      	</appender>
      

      In the tasks componing my processes, I get a logger through a static method that sets the MDC variable and then returns the logger, here is the code:

      import org.slf4j.Logger;
      import org.slf4j.LoggerFactory;
      import org.slf4j.MDC;
      
      public class myClass{
      
      	public static Logger getProcessLogger(Exchange exchange, String defaultFileName) {
      		initMDCContext(exchange, defaultFileName); //here MDC.put() is called
      		Logger processLogger = LoggerFactory
      				.getLogger("myLoggerName");
      		return processLogger;
      	}
      }
      

      In the final task of my processes I use the finalize_session_marker:

      } finally {
          Logger processLogger = myClass.getProcessLogger(exchange,"someDefaultString");
          processLogger.info(ClassicConstants.FINALIZE_SESSION_MARKER, "About to end the process");
      }
      

      All these tasks write correctly in the same file, if they are part of the same process, and at the end of every log i see the row:

      2015-04-23 09:46:25 INFO - About to end the process

      However the files corresponding my processes are still locked until i stop my application. This means neither the default <timeout>1 minute</timeout> nor ClassicConstants.FINALIZE_SESSION_MARKER are working.

      I'm quite new to logback so i don't know what to do to solve this issue.

      Attachments

        1. App.java
          3 kB
          Johann Alvarado
        2. logback.xml
          1 kB
          Johann Alvarado

        Activity

          People

            logback-dev Logback dev list
            emedves Enrico Medves
            Votes:
            1 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated: