Note that there are some explanatory texts on larger screens.

plurals
  1. POLogback file appender doesn't flush immediately
    text
    copied!<p>For some circumstances I need to force flushing in logback's file appender immediately. I've found in <a href="http://logback.qos.ch/manual/encoders.html#PatternLayoutEncoder" rel="nofollow noreferrer">docs</a> this option is enabled by default. Mysteriously this doesn't work. As I see in the sources underlying process involves <code>BufferedOutputSream</code> correctly. Is there any issues with <code>BufferedOutputSream.flush()</code> ? Probably this is rather related to the flushing issue.</p> <p><strong>Update</strong>: I found the issue on Windows XP Pro SP 3 and on Red Hat Enterprise Linux Server release 5.3 (Tikanga). I used these libs:</p> <pre><code>jcl-over-slf4j-1.6.6.jar logback-classic-1.0.6.jar logback-core-1.0.6.jar slf4j-api-1.6.6.jar </code></pre> <p>The <code>logback.xml</code> is:</p> <pre><code>&lt;configuration&gt; &lt;appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender"&gt; &lt;file&gt;/somepath/file.log&lt;/file&gt; &lt;rollingPolicy class="ch.qos.logback.core.rolling.FixedWindowRollingPolicy"&gt; &lt;fileNamePattern&gt;file.log.%i&lt;/fileNamePattern&gt; &lt;minIndex&gt;1&lt;/minIndex&gt; &lt;maxIndex&gt;3&lt;/maxIndex&gt; &lt;/rollingPolicy&gt; &lt;triggeringPolicy class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy"&gt; &lt;maxFileSize&gt;5MB&lt;/maxFileSize&gt; &lt;/triggeringPolicy&gt; &lt;encoder&gt; &lt;pattern&gt;%d{HH:mm:ss.SSS} [%thread] %-5level %logger - %msg%n&lt;/pattern&gt; &lt;/encoder&gt; &lt;/appender&gt; &lt;root level="debug"&gt; &lt;appender-ref ref="FILE"/&gt; &lt;/root&gt; &lt;/configuration&gt; </code></pre> <p><strong>Updated:</strong> I'd provide a unit test but that seems not so simple. Let me describe the issue more clearly.</p> <ol> <li>Event of logging occurred</li> <li>Event is passed into file appender</li> <li>Event is serialized with defined pattern</li> <li>Serialized message of event is passed to the file appender and is about to write out to output stream</li> <li>Writing to the stream is finished, output stream is flushed (I've checked the implementation). Note that <code>immidiateFlush</code> is true by default so method <code>flush()</code> is invoked explicitly</li> <li>No result in the file!</li> </ol> <p>A bit later when some underlying buffer was flowed the event appears in the file. So the question is: does output stream guarantee immediate flush?</p> <p>To be honest I've already solve this by implementing my own <code>ImmediateRollingFileAppender</code> that leverages facility of <code>FileDescriptor</code> of immediate syncing. Anybody interested in can follow <a href="https://stackoverflow.com/a/4072895/538514">this</a>.</p> <p>So this is not a logback issue.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload