<style>
/* Changing the layout to use less space for mobiles */
@media screen and (max-device-width: 480px), screen and (-webkit-min-device-pixel-ratio: 2) {
#email-body { min-width: 30em !important; }
#email-page { padding: 8px !important; }
#email-banner { padding: 8px 8px 0 8px !important; }
#email-avatar { margin: 1px 8px 8px 0 !important; padding: 0 !important; }
#email-fields { padding: 0 8px 8px 8px !important; }
#email-gutter { width: 0 !important; }
}
</style>
<div id="email-body">
<table id="email-wrap" align="center" border="0" cellpadding="0" cellspacing="0" style="background-color:#f0f0f0;color:#000000;width:100%;">
<tr valign="top">
<td id="email-page" style="padding:16px !important;">
<table align="center" border="0" cellpadding="0" cellspacing="0" style="background-color:#ffffff;border:1px solid #bbbbbb;color:#000000;width:100%;">
<tr valign="top">
<td bgcolor="#003366" style="background-color:#003366;color:#ffffff;font-family:Arial,FreeSans,Helvetica,sans-serif;font-size:12px;line-height:1;"><img src="http://jira.qos.ch/s/en_USb9v8he-418945332/850/25/_/jira-logo-scaled.png" alt="" style="vertical-align:top;" /></td>
</tr><tr valign="top">
<td id="email-banner" style="padding:32px 32px 0 32px;">
<table align="left" border="0" cellpadding="0" cellspacing="0" width="100%" style="width:100%;">
<tr valign="top">
<td style="color:#505050;font-family:Arial,FreeSans,Helvetica,sans-serif;padding:0;">
<img id="email-avatar" src="http://jira.qos.ch/secure/useravatar?avatarId=10122" alt="" height="48" width="48" border="0" align="left" style="padding:0;margin: 0 16px 16px 0;" />
<div id="email-action" style="padding: 0 0 8px 0;font-size:12px;line-height:18px;">
<a class="user-hover" rel="michal" id="email_michal" href="http://jira.qos.ch/secure/ViewProfile.jspa?name=michal" style="color:#326ca6;">Michal Jacykiewicz</a>
created <img src="http://jira.qos.ch/images/icons/issuetypes/bug.png" height="16" width="16" border="0" align="absmiddle" alt="Bug"> <a style='color:#326ca6;text-decoration:none;' href='http://jira.qos.ch/browse/LOGBACK-917'>LOGBACK-917</a>
</div>
<div id="email-summary" style="font-size:16px;line-height:20px;padding:2px 0 16px 0;">
<a style='color:#326ca6;text-decoration:none;' href='http://jira.qos.ch/browse/LOGBACK-917'><strong>FixedWindowRollingPolicy + SizeBasedTriggeringPolicy do not respect maxFileSize</strong></a>
</div>
</td>
</tr>
</table>
</td>
</tr>
<tr valign="top">
<td id="email-fields" style="padding:0 32px 32px 32px;">
<table border="0" cellpadding="0" cellspacing="0" style="padding:0;text-align:left;width:100%;" width="100%">
<tr valign="top">
<td id="email-gutter" style="width:64px;white-space:nowrap;"></td>
<td>
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr valign="top">
<td style="color:#000000;font-family:Arial,FreeSans,Helvetica,sans-serif;font-size:12px;padding:0 10px 10px 0;white-space:nowrap;">
<strong style="font-weight:normal;color:#505050;">Issue Type:</strong>
</td>
<td style="color:#000000;font-family:Arial,FreeSans,Helvetica,sans-serif;font-size:12px;padding:0 0 10px 0;width:100%;">
<img src="http://jira.qos.ch/images/icons/issuetypes/bug.png" height="16" width="16" border="0" align="absmiddle" alt="Bug"> Bug
</td>
</tr> <tr valign="top">
<td style="color:#000000;font-family:Arial,FreeSans,Helvetica,sans-serif;font-size:12px;padding:0 10px 10px 0;white-space:nowrap;">
<strong style="font-weight:normal;color:#505050;">Affects Versions:</strong>
</td>
<td style="color:#000000;font-family:Arial,FreeSans,Helvetica,sans-serif;font-size:12px;padding:0 0 10px 0;width:100%;">
1.0.13 </td>
</tr>
<tr valign="top">
<td style="color:#000000;font-family:Arial,FreeSans,Helvetica,sans-serif;font-size:12px;padding:0 10px 10px 0;white-space:nowrap;">
<strong style="font-weight:normal;color:#505050;">Assignee:</strong>
</td>
<td style="color:#000000;font-family:Arial,FreeSans,Helvetica,sans-serif;font-size:12px;padding:0 0 10px 0;width:100%;">
<a class="user-hover" rel="logback-dev@qos.ch" id="email_logback-dev@qos.ch" href="http://jira.qos.ch/secure/ViewProfile.jspa?name=logback-dev%40qos.ch" style="color:#326ca6;">Logback dev list</a>
</td>
</tr> <tr valign="top">
<td style="color:#000000;font-family:Arial,FreeSans,Helvetica,sans-serif;font-size:12px;padding:0 10px 10px 0;white-space:nowrap;">
<strong style="font-weight:normal;color:#505050;">Attachments:</strong>
</td>
<td style="color:#000000;font-family:Arial,FreeSans,Helvetica,sans-serif;font-size:12px;padding:0 0 10px 0;width:100%;">
logback-test.xml </td>
</tr>
<tr valign="top">
<td style="color:#000000;font-family:Arial,FreeSans,Helvetica,sans-serif;font-size:12px;padding:0 10px 10px 0;white-space:nowrap;">
<strong style="font-weight:normal;color:#505050;">Components:</strong>
</td>
<td style="color:#000000;font-family:Arial,FreeSans,Helvetica,sans-serif;font-size:12px;padding:0 0 10px 0;width:100%;">
logback-core </td>
</tr>
<tr valign="top">
<td style="color:#000000;font-family:Arial,FreeSans,Helvetica,sans-serif;font-size:12px;padding:0 10px 10px 0;white-space:nowrap;">
<strong style="font-weight:normal;color:#505050;">Created:</strong>
</td>
<td style="color:#000000;font-family:Arial,FreeSans,Helvetica,sans-serif;font-size:12px;padding:0 0 10px 0;width:100%;">
05/Nov/13 5:19 PM
</td>
</tr> <tr valign="top">
<td style="color:#000000;font-family:Arial,FreeSans,Helvetica,sans-serif;font-size:12px;padding:0 10px 10px 0;white-space:nowrap;">
<strong style="font-weight:normal;color:#505050;">Description:</strong>
</td>
<td style="color:#000000;font-family:Arial,FreeSans,Helvetica,sans-serif;font-size:12px;padding:0 0 10px 0;width:100%;">
<p style='margin-top:0;margin-bottom:10px;'>The following JUnit test case shows that the latest 1.0.13 Logback does not limit the size of the files as requested. Depending of the maxFileSize, the inaccuracy varies between 15% and 600%. E.g.</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
java.lang.AssertionError: nogzip_1mb_each_1max.log.1 size is 3.3MB which is 328% of 1.0MB requested
java.lang.AssertionError: nogzip_1mb_each_5max.log.1 size is 6.6MB which is 655% of 1.0MB requested
java.lang.AssertionError: nogzip_1mb_each_9max.log.1 size is 6.6MB which is 655% of 1.0MB requested
java.lang.AssertionError: nogzip_10mb_each_1max.log.1 size is 13.2MB which is 132% of 10.0MB requested
java.lang.AssertionError: nogzip_10mb_each_5max.log.1 size is 13.2MB which is 132% of 10.0MB requested
java.lang.AssertionError: nogzip_20mb_each_3max.log.1 size is 23.0MB which is 115% of 20.0MB requested
</pre>
</div></div>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
<span class="code-keyword">package</span> third.party.logback;
<span class="code-keyword">import</span> <span class="code-keyword">static</span> org.junit.Assert.*;
<span class="code-keyword">import</span> java.io.File;
<span class="code-keyword">import</span> java.util.Date;
<span class="code-keyword">import</span> java.util.Random;
<span class="code-keyword">import</span> org.junit.BeforeClass;
<span class="code-keyword">import</span> org.junit.Test;
<span class="code-keyword">import</span> org.slf4j.LoggerFactory;
<span class="code-keyword">import</span> ch.qos.logback.classic.Logger;
<span class="code-keyword">import</span> ch.qos.logback.classic.LoggerContext;
<span class="code-keyword">import</span> ch.qos.logback.classic.encoder.PatternLayoutEncoder;
<span class="code-keyword">import</span> ch.qos.logback.classic.spi.ILoggingEvent;
<span class="code-keyword">import</span> ch.qos.logback.core.rolling.FixedWindowRollingPolicy;
<span class="code-keyword">import</span> ch.qos.logback.core.rolling.RollingFileAppender;
<span class="code-keyword">import</span> ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy;
<span class="code-keyword">public</span> class SizeRotationTest {
<span class="code-keyword">private</span> <span class="code-keyword">static</span> File _tmpDir;
@BeforeClass
<span class="code-keyword">public</span> <span class="code-keyword">static</span> void setup() <span class="code-keyword">throws</span> Exception {
_tmpDir = <span class="code-keyword">new</span> File(<span class="code-object">System</span>.getProperty(<span class="code-quote">"java.io.tmpdir"</span>) + <span class="code-quote">"/fixedwindowlogbacktest/"</span> + <span class="code-object">System</span>.currentTimeMillis());
<span class="code-keyword">for</span>(<span class="code-object">String</span> p : <span class="code-keyword">new</span> <span class="code-object">String</span>[]{ <span class="code-quote">"java.vendor"</span>, <span class="code-quote">"java.version"</span>, <span class="code-quote">"os.name"</span>, <span class="code-quote">"os.version"</span>, <span class="code-quote">"os.arch"</span> } ) {
<span class="code-object">System</span>.out.println(p + <span class="code-quote">"="</span> + <span class="code-object">System</span>.getProperty(p));
}
<span class="code-object">System</span>.out.println(<span class="code-quote">"using "</span> + _tmpDir.getAbsolutePath());
}
<span class="code-keyword">private</span> <span class="code-keyword">static</span> void verifyFileSize(File file, <span class="code-object">long</span> requestedMaxSize) {
<span class="code-object">String</span> msg = <span class="code-object">String</span>.format(<span class="code-quote">"%s size is %.1fMB which is %.0f%% of %.1fMB requested"</span>,
file.getName(), file.length()/1024f/1024,
100f * file.length() / requestedMaxSize, requestedMaxSize/1024f/1024);
assertTrue(msg, file.length() <= requestedMaxSize);
}
<span class="code-keyword">private</span> void doTest(<span class="code-keyword">final</span> <span class="code-object">String</span> name, <span class="code-object">boolean</span> compress, <span class="code-object">int</span> maxFiles, <span class="code-object">long</span> maxSize) {
File testDir = <span class="code-keyword">new</span> File(_tmpDir, name);
File basename = <span class="code-keyword">new</span> File(testDir, name + <span class="code-quote">".log"</span>);
File rotated = <span class="code-keyword">new</span> File(testDir, name + (compress ? <span class="code-quote">".log.%i.gz"</span> : <span class="code-quote">".log.%i"</span>));
LoggerContext ctx = (LoggerContext) LoggerFactory.getILoggerFactory();
FixedWindowRollingPolicy rollingPolicy = <span class="code-keyword">new</span> FixedWindowRollingPolicy();
rollingPolicy.setContext(ctx);
rollingPolicy.setMinIndex(1);
rollingPolicy.setMaxIndex(maxFiles - 1);
rollingPolicy.setFileNamePattern(rotated.getPath());
SizeBasedTriggeringPolicy<ILoggingEvent> triggeringPolicy = <span class="code-keyword">new</span> SizeBasedTriggeringPolicy<ILoggingEvent>(<span class="code-object">String</span>.valueOf(maxSize));
RollingFileAppender<ILoggingEvent> appender = <span class="code-keyword">new</span> RollingFileAppender<ILoggingEvent>();
appender.setFile(basename.getPath());
appender.setAppend(<span class="code-keyword">false</span>);
appender.setRollingPolicy(rollingPolicy);
appender.setTriggeringPolicy(triggeringPolicy);
rollingPolicy.setParent(appender);
rollingPolicy.start();
triggeringPolicy.start();
PatternLayoutEncoder layout = <span class="code-keyword">new</span> PatternLayoutEncoder();
layout.setPattern(<span class="code-quote">"%d{YYYY-MM-dd HH:mm:ss.SSS} [%thread] %level %logger %msg%n"</span>);
layout.setContext(ctx);
layout.start();
appender.setEncoder(layout);
appender.setContext(ctx);
appender.start();
Logger log = (Logger) LoggerFactory.getLogger(name);
log.addAppender(appender);
<span class="code-comment">// <span class="code-keyword">do</span> log quite a few msgs
</span> Random rnd = <span class="code-keyword">new</span> Random();
<span class="code-object">String</span> msg = <span class="code-quote">"{} During the application {} in the <span class="code-keyword">case</span> <span class="code-object">long</span>-lived application on {} when {} is another random"</span>;
<span class="code-keyword">for</span>(<span class="code-object">int</span> i = 0; i < 200000; ++i) {
log.info(msg, <span class="code-object">System</span>.nanoTime(), <span class="code-keyword">new</span> Date(), rnd.nextGaussian());
}
<span class="code-comment">// verify all file sizes
</span> <span class="code-keyword">for</span>(<span class="code-object">int</span> i = 1; i < maxFiles; ++i) {
<span class="code-object">String</span> file = <span class="code-object">String</span>.format(rotated.getPath().replace(<span class="code-quote">"%i"</span>, <span class="code-quote">"%d"</span>), i);
verifyFileSize(<span class="code-keyword">new</span> File(file), maxSize);
}
verifyFileSize(basename, maxSize);
}
@Test <span class="code-keyword">public</span> void test_NoGzip_2rot_1MB() { doTest(<span class="code-quote">"nogzip_1mb_each_1max"</span>, <span class="code-keyword">false</span>, 2, 1 * 1024 * 1024); }
@Test <span class="code-keyword">public</span> void test_NoGzip_5rot_1MB() { doTest(<span class="code-quote">"nogzip_1mb_each_5max"</span>, <span class="code-keyword">false</span>, 5, 1 * 1024 * 1024); }
@Test <span class="code-keyword">public</span> void test_NoGzip_9rot_1MB() { doTest(<span class="code-quote">"nogzip_1mb_each_9max"</span>, <span class="code-keyword">false</span>, 9, 1 * 1024 * 1024); }
@Test <span class="code-keyword">public</span> void test_NoGzip_2rot_10MB() { doTest(<span class="code-quote">"nogzip_10mb_each_1max"</span>, <span class="code-keyword">false</span>, 2, 10 * 1024 * 1024); }
@Test <span class="code-keyword">public</span> void test_NoGzip_5rot_10MB() { doTest(<span class="code-quote">"nogzip_10mb_each_5max"</span>, <span class="code-keyword">false</span>, 5, 10 * 1024 * 1024); }
@Test <span class="code-keyword">public</span> void test_NoGzip_3rot_20MB() { doTest(<span class="code-quote">"nogzip_20mb_each_3max"</span>, <span class="code-keyword">false</span>, 3, 20 * 1024 * 1024); }
<span class="code-comment">// gzipped
</span> @Test <span class="code-keyword">public</span> void test_gzipped_2rot_1MB() { doTest(<span class="code-quote">"gzipped_1mb_each_2max"</span>, <span class="code-keyword">true</span>, 2, 1 * 1024 * 1024); }
@Test <span class="code-keyword">public</span> void test_gzipped_5rot_1MB() { doTest(<span class="code-quote">"gzipped_1mb_each_5max"</span>, <span class="code-keyword">true</span>, 5, 1 * 1024 * 1024); }
@Test <span class="code-keyword">public</span> void test_gzipped_2rot_10MB() { doTest(<span class="code-quote">"gzipped_10mb_each_2max"</span>, <span class="code-keyword">true</span>, 2, 10 * 1024 * 1024); }
}
</pre>
</div></div>
</td>
</tr>
<tr valign="top">
<td style="color:#000000;font-family:Arial,FreeSans,Helvetica,sans-serif;font-size:12px;padding:0 10px 10px 0;white-space:nowrap;">
<strong style="font-weight:normal;color:#505050;">Environment:</strong>
</td>
<td style="color:#000000;font-family:Arial,FreeSans,Helvetica,sans-serif;font-size:12px;padding:0 0 10px 0;width:100%;">
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
java.vendor=Sun Microsystems Inc.
java.version=1.6.0_45
os.name=Windows 7
os.version=6.1
os.arch=amd64
</pre>
</div></div>
</td>
</tr>
<tr valign="top">
<td style="color:#000000;font-family:Arial,FreeSans,Helvetica,sans-serif;font-size:12px;padding:0 10px 10px 0;white-space:nowrap;">
<strong style="font-weight:normal;color:#505050;">Project:</strong>
</td>
<td style="color:#000000;font-family:Arial,FreeSans,Helvetica,sans-serif;font-size:12px;padding:0 0 10px 0;width:100%;">
<a style="color:#326ca6;" href="http://jira.qos.ch/browse/LOGBACK">logback</a>
</td>
</tr> <tr valign="top">
<td style="color:#000000;font-family:Arial,FreeSans,Helvetica,sans-serif;font-size:12px;padding:0 10px 10px 0;white-space:nowrap;">
<strong style="font-weight:normal;color:#505050;">Priority:</strong>
</td>
<td style="color:#000000;font-family:Arial,FreeSans,Helvetica,sans-serif;font-size:12px;padding:0 0 10px 0;width:100%;">
<img src="http://jira.qos.ch/images/icons/priorities/critical.png" height="16" width="16" border="0" align="absmiddle" alt="Critical"> Critical
</td>
</tr>
<tr valign="top">
<td style="color:#000000;font-family:Arial,FreeSans,Helvetica,sans-serif;font-size:12px;padding:0 10px 10px 0;white-space:nowrap;">
<strong style="font-weight:normal;color:#505050;">Reporter:</strong>
</td>
<td style="color:#000000;font-family:Arial,FreeSans,Helvetica,sans-serif;font-size:12px;padding:0 0 10px 0;width:100%;">
<a class="user-hover" rel="michal" id="email_michal" href="http://jira.qos.ch/secure/ViewProfile.jspa?name=michal" style="color:#326ca6;">Michal Jacykiewicz</a>
</td>
</tr> </table>
</td>
</tr>
</table>
</td>
</tr>
</table>
</td><!-- End #email-page -->
</tr>
<tr valign="top">
<td style="color:#505050;font-family:Arial,FreeSans,Helvetica,sans-serif;font-size:10px;line-height:14px;padding: 0 16px 16px 16px;text-align:center;">
This message is automatically generated by JIRA.<br />
If you think it was sent incorrectly, please contact your JIRA administrators<br />
For more information on JIRA, see: <a style='color:#326ca6;' href='http://www.atlassian.com/software/jira'>http://www.atlassian.com/software/jira</a>
</td>
</tr>
</table><!-- End #email-wrap -->
</div><!-- End #email-body -->