logback-dev
Threads by month
- ----- 2025 -----
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2024 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2023 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2022 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2021 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2020 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2019 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2018 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2017 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2016 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2015 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2014 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2013 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2012 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2011 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2010 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2009 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2008 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2007 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2006 -----
- December
- November
- October
- September
- August
- July
- June
- May
August 2009
- 13 participants
- 104 discussions

svn commit: r2423 - in logback/trunk/logback-site/src/site/pages: . manual
by noreply.ceki@qos.ch 08 Aug '09
by noreply.ceki@qos.ch 08 Aug '09
08 Aug '09
Author: ceki
Date: Sat Aug 8 17:28:39 2009
New Revision: 2423
Modified:
logback/trunk/logback-site/src/site/pages/index.html
logback/trunk/logback-site/src/site/pages/manual/appenders.html
logback/trunk/logback-site/src/site/pages/manual/architecture.html
logback/trunk/logback-site/src/site/pages/manual/filters.html
logback/trunk/logback-site/src/site/pages/manual/introduction.html
logback/trunk/logback-site/src/site/pages/manual/jmxConfig.html
logback/trunk/logback-site/src/site/pages/manual/layouts.html
logback/trunk/logback-site/src/site/pages/manual/loggingSeparation.html
logback/trunk/logback-site/src/site/pages/manual/mdc.html
logback/trunk/logback-site/src/site/pages/manual/migrationFromLog4j.html
logback/trunk/logback-site/src/site/pages/manual/onJoran.html
Log:
- prettified logback manual pages
Modified: logback/trunk/logback-site/src/site/pages/index.html
==============================================================================
--- logback/trunk/logback-site/src/site/pages/index.html (original)
+++ logback/trunk/logback-site/src/site/pages/index.html Sat Aug 8 17:28:39 2009
@@ -39,7 +39,7 @@
significantly improved version of log4j. Moreover, logback-classic
natively implements the <a href="http://www.slf4j.org">SLF4J
API</a> so that you can readily switch back and forth between
- logback and other logging systems such as log4j or
+ logback and other logging frameworks such as log4j or
java.util.logging (JUL).
</p>
Modified: logback/trunk/logback-site/src/site/pages/manual/appenders.html
==============================================================================
--- logback/trunk/logback-site/src/site/pages/manual/appenders.html (original)
+++ logback/trunk/logback-site/src/site/pages/manual/appenders.html Sat Aug 8 17:28:39 2009
@@ -7,10 +7,11 @@
<link rel="stylesheet" type="text/css" href="../css/common.css" />
<link rel="stylesheet" type="text/css" href="../css/screen.css" media="screen" />
<link rel="stylesheet" type="text/css" href="../css/_print.css" media="print" />
-
+ <link rel="stylesheet" type="text/css" href="../css/prettify.css" media="screen" /
</head>
- <body>
+ <body onload="prettyPrint()">
<script type="text/javascript">prefix='../';</script>
+ <script type="text/javascript" src="../js/prettify.js"></script>
<script src="../templates/header.js" type="text/javascript"></script>
<div id="left">
<noscript>Please turn on Javascript to view this menu</noscript>
@@ -46,7 +47,7 @@
interface. The salient methods of this interface are summarized
below:
</p>
- <div class="source"><pre>package ch.qos.logback.core;
+ <pre class="prettyprint source">package ch.qos.logback.core;
import ch.qos.logback.core.spi.ContextAware;
import ch.qos.logback.core.spi.FilterAttachable;
@@ -61,7 +62,7 @@
public Layout<E> getLayout();
public void setName(String name);
-}</pre></div>
+}</pre>
<p>Most of the methods in the <code>Appender</code> interface are
made of setter and getter methods. A notable exception is the
@@ -111,7 +112,7 @@
is by presenting an excerpt of actual source code.
</p>
-<div class="source"><pre>public synchronized void doAppend(E eventObject) {
+<pre class="prettyprint source">public synchronized void doAppend(E eventObject) {
// prevent re-entry.
if (guard) {
@@ -139,7 +140,7 @@
} finally {
guard = false;
}
-}</pre></div>
+}</pre>
<p>This implementation of the <code>doAppend()</code> method is
synchronized. It follows that logging to the same appender from
@@ -292,7 +293,7 @@
<em>Example 4.<span class="autoEx"/>: Exiting an application without flushing (<a href="../xref/chapter4/ExitWoes1.html">logback-examples/src/main/java/chapter4/ExitWoes1.java</a>)</em>
- <p class="source">package chapter4;
+ <pre class="prettyprint source">package chapter4;
import java.io.FileOutputStream;
import java.io.OutputStream;
@@ -327,7 +328,7 @@
logger.debug("Hello world.");
}
-}</p>
+}</pre>
<p>This example creates a <code>WriterAppender</code> that uses an
<code>OutputStreamWriter</code> wrapping a
@@ -404,7 +405,7 @@
</p>
<em>Example 4.<span class="autoEx"/>: ConsoleAppender configuration (logback-examples/src/main/java/chapter4/conf/logback-Console.xml)</em>
- <p class="source"><configuration>
+ <pre class="prettyprint source"><configuration>
<b><appender name="STDOUT"
class="ch.qos.logback.core.ConsoleAppender">
@@ -416,7 +417,7 @@
<root level="debug">
<appender-ref ref="STDOUT" />
</root>
-</configuration></p>
+</configuration></pre>
<p>After you have set your current path to the
<em>logback-examples</em> directory, you can give the above
@@ -576,7 +577,7 @@
</p>
<em>Example 4.<span class="autoEx"/>: FileAppender configuration (logback-examples/src/main/java/chapter4/conf/logback-fileAppender.xml)</em>
- <p class="source"><configuration>
+ <pre class="prettyprint source"><configuration>
<b><appender name="FILE" class="ch.qos.logback.core.FileAppender">
<File>testFile.log</File>
@@ -590,7 +591,7 @@
<root level="debug">
<appender-ref ref="FILE" />
</root>
-</configuration></p>
+</configuration></pre>
<p>After changing the current directory to
<em>logback-examples</em>, run this example by launching the
@@ -717,7 +718,7 @@
<p>The <code>RollingPolicy</code> interface is presented below:</p>
- <p class="source">package ch.qos.logback.core.rolling;
+ <pre class="prettyprint source">package ch.qos.logback.core.rolling;
import ch.qos.logback.core.FileAppender;
import ch.qos.logback.core.spi.LifeCycle;
@@ -727,7 +728,7 @@
<b>public void rollover() throws RolloverFailure;</b>
public String getNewActiveFileName();
public void setParent(FileAppender appender);
-}</p>
+}</pre>
<p>The <code>rollover</code> method proceeds to the file change,
renaming or deletion. The <code>getNewActiveFileName()</code>
@@ -895,7 +896,7 @@
<em>Example 4.<span class="autoEx"/>: Sample configuration of a <code>RollingFileAppender</code> using a
<code>FixedWindowRollingPolicy</code> (logback-examples/src/main/java/chapter4/conf/logback-RollingFixedWindow.xml)</em>
- <p class="source"><configuration>
+ <pre class="prettyprint source"><configuration>
<appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
<b><File>test.log</File></b>
@@ -916,7 +917,7 @@
<root level="debug">
<appender-ref ref="FILE" />
</root>
-</configuration></p>
+</configuration></pre>
<h4>
<a name="TimeBasedRollingPolicy" href="#TimeBasedRollingPolicy">TimeBasedRollingPolicy</a>
@@ -926,7 +927,12 @@
href="../xref/ch/qos/logback/core/rolling/TimeBasedRollingPolicy.html">
<code>TimeBasedRollingPolicy</code></a> is possibly the most
popular rolling policy. It defines a rollover policy based on time,
- say by day or by month.
+ say by day or by month. <code>TimeBasedRollingPolicy</code> is
+ particular in the sense that it simultaneously implements both the
+ <code>RollingPolicy</code> as well as the
+ <code>TriggeringPolicy</code> interfaces. The
+ <code>TriggeringPolicy</code> interface will be presented in the
+ next sub-section.
</p>
<p><code>TimeBasedRollingPolicy</code>'s admits two properties, the
@@ -1118,7 +1124,7 @@
<em>Example 4.<span class="autoEx"/>: Sample configuration of a <code>RollingFileAppender</code> using a
<code>TimeBasedRollingPolicy</code> (logback-examples/src/main/java/chapter4/conf/logback-RollingTimeBased.xml)</em>
- <p class="source"><configuration>
+ <pre class="prettyprint source"><configuration>
<appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
<File>logFile.log</File>
<b><rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
@@ -1135,7 +1141,7 @@
<root level="debug">
<appender-ref ref="FILE" />
</root>
-</configuration></p>
+</configuration></pre>
<p>The next configuration sample illustrates the use
<code>RollingFileAppender</code> associated with
@@ -1145,7 +1151,7 @@
<em>Example 4.<span class="autoEx"/>: Sample configuration of a <code>RollingFileAppender</code> using a
<code>TimeBasedRollingPolicy</code> (logback-examples/src/main/java/chapter4/conf/logback-PrudentTimeBasedRolling.xml)</em>
- <p class="source"><configuration>
+ <pre class="prettyprint source"><configuration>
<appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
<b><!-- Support multiple-JVM writing to the same log file --></b>
<b><Prudent>true</Prudent></b>
@@ -1162,24 +1168,61 @@
<root level="debug">
<appender-ref ref="FILE" />
</root>
-</configuration></p>
+</configuration></pre>
+
+
+ <h3>
+ <a name="SizeAndTimeBasedFNATP"
+ href="#SizeAndTimeBasedFNATP">Size <b>and</b> time based archiving</a>
+ </h3>
+ <p>You may sometimes wish to archive files essentialy by date but
+ at the same time limit the size of each log file, in particular if
+ post-processing tools impose size limits.</p>
+ <em>Example 4.<span class="autoEx"/>: Sample configuration of a <code>RollingFileAppender</code> using a
+ <code>TimeBasedRollingPolicy</code> (logback-examples/src/main/java/chapter4/conf/logback-PrudentTimeBasedRolling.xml)</em>
+ <pre class="prettyprint source"><configuration>
+ <appender name="ROLLING"
+ class="ch.qos.logback.core.rolling.RollingFileAppender">
+ <File>${randomOutputDir}z${testId}</File>
+ <rollingPolicy
+ class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
+ <FileNamePattern>
+ ${randomOutputDir}${testId}-%d{yyyy-MM-dd_HH_mm_ss}.%i
+ </FileNamePattern>
+ <TimeBasedFileNamingAndTriggeringPolicy
+ class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
+ <MaxFileSize>${sizeThreshold}</MaxFileSize>
+ </TimeBasedFileNamingAndTriggeringPolicy>
+ </rollingPolicy>
+ <layout>
+ <Pattern>%msg%n</Pattern>
+ </layout>
+ </appender>
+ <root level="debug">
+ <appender-ref ref="ROLLING" />
+ </root>
+
+</configuration></pre>
+
+
+
<h3>
- <a name="TriggeringPolicy" href="#TriggeringPolicy">Triggering policies</a>
+ <a name="TriggeringPolicy" href="#TriggeringPolicy">Triggering policy interface</a>
</h3>
<p><a
href="../xref/ch/qos/logback/core/rolling/TriggeringPolicy.html"><code>TriggeringPolicy</code></a>
implementations are responsible for instructing the
- <code>RollingFileAppender</code> to rollover.</p>
+ <code>RollingFileAppender</code> when to rollover.</p>
<p>The <code>TriggeringPolicy</code> interface contains only one
method.</p>
- <p class="source">package ch.qos.logback.core.rolling;
+ <pre class="prettyprint source">package ch.qos.logback.core.rolling;
import java.io.File;
import ch.qos.logback.core.spi.LifeCycle;
@@ -1187,7 +1230,7 @@
public interface TriggeringPolicy<E> extends LifeCycle {
<b>public boolean isTriggeringEvent(final File activeFile, final <E> event);</b>
-}</p>
+}</pre>
<p>The <code>isTriggeringEvent()</code> method takes as parameters
the active file, and the logging event currently being
@@ -1228,7 +1271,7 @@
<em>Example 4.<span class="autoEx"/>: Sample configuration of a <code>RollingFileAppender</code> using a
<code>SizeBasedTriggeringPolicy</code> (logback-examples/src/main/java/chapter4/conf/logback-RollingSizeBased.xml)</em>
- <p class="source"><configuration>
+ <pre class="prettyprint source"><configuration>
<appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
<File>testFile.log</File>
<rollingPolicy class="ch.qos.logback.core.rolling.FixedWindowRollingPolicy">
@@ -1248,7 +1291,7 @@
<root level="debug">
<appender-ref ref="FILE" />
</root>
-</configuration></p>
+</configuration></pre>
<!-- XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXx -->
@@ -1446,7 +1489,7 @@
</p>
<em>Example 4.<span class="autoEx"/>: SocketAppender configuration (logback-examples/src/main/java/chapter4/socket/client1.xml)</em>
-<div class="source"><pre><configuration>
+<pre class="prettyprint source"><configuration>
<appender name="SOCKET" class="ch.qos.logback.classic.net.SocketAppender">
<RemoteHost>${host}</RemoteHost>
@@ -1459,7 +1502,7 @@
<appender-ref ref="SOCKET" />
</root>
-</configuration></pre></div>
+</configuration></pre>
<p>
@@ -1721,10 +1764,10 @@
naming server one would write:
</p>
-<div class="source"><pre>Properties env = new Properties();
+<pre class="prettyprint source">Properties env = new Properties();
env.put(Context.INITIAL_CONTEXT_FACTORY, "org.apache.activemq.jndi.ActiveMQInitialContextFactory");
env.put(Context.PROVIDER_URL, "tcp://<em>hostname</em>:61616");
-Context ctx = new InitialContext(env);</pre></div>
+Context ctx = new InitialContext(env);</pre>
<p>
where <em>hostname</em> is the host where the ActiveMQ server is running.
@@ -1792,7 +1835,7 @@
Its most important method, <code>doAppend()</code> is listed below:
</p>
-<div class="source"><pre>public void append(ILoggingEvent event) {
+<pre class="prettyprint source">public void append(ILoggingEvent event) {
if (!isStarted()) {
return;
}
@@ -1810,7 +1853,7 @@
}
addError("Could not publish message in JMSTopicAppender [" + name + "].", e);
}
-}</pre></div>
+}</pre>
<p>
The <code>isStarted()</code> method allows the appender to check
@@ -1845,7 +1888,7 @@
is implemented as follows:
</p>
-<div class="source"><pre>public void onMessage(javax.jms.Message message) {
+<pre class="prettyprint source">public void onMessage(javax.jms.Message message) {
ILoggingEvent event;
try {
if (message instanceof ObjectMessage) {
@@ -1860,7 +1903,7 @@
} catch (JMSException jmse) {
logger.error("Exception thrown while processing incoming message.", jmse);
}
-}</pre></div>
+}</pre>
<p>
The <code>onMessage()</code> method begins by retrieving the logging event's payload.
@@ -1906,7 +1949,7 @@
</p>
<em>Example 4.<span class="autoEx"/>: JMSTopicAppender configuration (logback-examples/src/main/java/chapter4/conf/logback-JMSTopic.xml)</em>
-<div class="source"><pre><configuration>
+<pre class="prettyprint source"><configuration>
<appender name="Topic"
class="ch.qos.logback.classic.net.JMSTopicAppender">
@@ -1923,7 +1966,7 @@
<root level="debug">
<appender-ref ref="Topic" />
</root>
-</configuration></pre></div>
+</configuration></pre>
<a name="JMSQueueAppender"></a>
<h3>JMSQueueAppender</h3>
@@ -1974,7 +2017,7 @@
similar to that of a <code>JMSTopicAppender</code>.
</p>
<em>Example 4.<span class="autoEx"/>: JMSQueueAppender configuration (logback-examples/src/main/java/chapter4/conf/logback-JMSQueue.xml)</em>
-<div class="source"><pre><configuration>
+<pre class="prettyprint source"><configuration>
<appender name="Queue"
class="ch.qos.logback.classic.net.JMSQueueAppender">
@@ -1991,7 +2034,7 @@
<root level="debug">
<appender-ref ref="Queue" />
</root>
-</configuration></pre></div>
+</configuration></pre>
<h3><a name="SMTPAppender" href="#SMTPAppender">SMTPAppender</a></h3>
@@ -2185,7 +2228,7 @@
</p>
<em>Example 4.<span class="autoEx"/>: A sample <code>SMTPAppender</code> configuration (logback-examples/src/main/java/chapter4/mail/mail1.xml)</em>
- <p class="source"><configuration>
+ <pre class="prettyprint source"><configuration>
<appender name="EMAIL" class="ch.qos.logback.classic.net.SMTPAppender">
<SMTPHost>ADDRESS-OF-YOUR-SMTP-HOST</SMTPHost>
<To>EMAIL-DESTINATION</To>
@@ -2200,7 +2243,7 @@
<root level="debug">
<appender-ref ref="EMAIL" />
</root>
-</configuration></p>
+</configuration></pre>
<p>Before trying out <code>chapter4.mail.Email</code> application
with the above configuration file, you must set the <span
@@ -2227,14 +2270,12 @@
relevant part of <em>mail2.xml</em>.
</p>
-<div class="source"><pre>
- <appender name="EMAIL" class="ch.qos.logback.classic.net.SMTPAppender">
- <SMTPHost>${smtpHost}</SMTPHost>
- <To>${to}</To>
- <From>${from}</From>
- <layout class="ch.qos.logback.classic.html.HTMLLayout"/>
- </appender>
-</pre></div>
+ <pre class="prettyprint source"><appender name="EMAIL" class="ch.qos.logback.classic.net.SMTPAppender">
+ <SMTPHost>${smtpHost}</SMTPHost>
+ <To>${to}</To>
+ <From>${from}</From>
+ <layout class="ch.qos.logback.classic.html.HTMLLayout"/>
+</appender></pre>
<p>You can pass the required parameters on the command line:</p>
@@ -2300,7 +2341,7 @@
<em>Example 4.<span class="autoEx"/>: A <code>EventEvaluator</code> implementation
that evaluates to <code>true</code> every 1024th event (<a href="../xref/chapter4/mail/CounterBasedEvaluator.html">logback-examples/src/main/java/chapter4/mail/CounterBasedEvaluator.java</a>)</em>
-<div class="source"><pre>package chapter4.mail;
+<pre class="prettyprint source">package chapter4.mail;
import ch.qos.logback.core.boolex.EvaluationException;
import ch.qos.logback.core.boolex.EventEvaluator;
@@ -2332,7 +2373,7 @@
public void setName(String name) {
this.name = name;
}
-}</pre></div>
+}</pre>
<p>
Note that this implementation extends <code>ContextAwareBase</code> and
@@ -2352,7 +2393,7 @@
<em>Example 4.<span class="autoEx"/>: <code>SMTPAppender</code> with custom
<code>Evaluator</code> and buffer size (logback-examples/src/main/java/chapter4/mail/mail3.xml)</em>
-<div class="source"><pre><configuration>
+<pre class="prettyprint source"><configuration>
<appender name="EMAIL" class="ch.qos.logback.classic.net.SMTPAppender">
<b><Evaluator class="chapter4.mail.CounterBasedEvaluator" /></b>
<BufferSize>1050</BufferSize>
@@ -2365,8 +2406,7 @@
<root level="debug">
<appender-ref ref="EMAIL" />
</root>
-</configuration></pre></div>
-
+</configuration></pre>
<h3><a name="smtpAuthentication"
@@ -2389,7 +2429,7 @@
<em>Example 4.<span class="autoEx"/>: <code>SMTPAppender</code> to Gmail using SSL (logback-examples/src/main/java/chapter4/mail/gmailSSL.xml)</em>
- <p class="source"><configuration>
+ <pre class="prettyprint source"><configuration>
<appender name="EMAIL" class="ch.qos.logback.classic.net.SMTPAppender">
<b><SMTPHost>smtp.gmail.com</SMTPHost></b>
<b><SMTPPort>465</SMTPPort></b>
@@ -2409,7 +2449,7 @@
<root level="debug">
<appender-ref ref="EMAIL" />
</root>
-</configuration></p>
+</configuration></pre>
<h3><a name="gmailSTARTTLS" href="#gmailSTARTTLS">SMTPAppender for Gmail
@@ -2420,7 +2460,7 @@
<em>Example 4.<span class="autoEx"/>: <code>SMTPAppender</code> to GMAIL using STARTTLS (logback-examples/src/main/java/chapter4/mail/gmailSTARTTLS.xml)</em>
- <p class="source"><configuration>
+ <pre class="prettyprint source"><configuration>
<appender name="EMAIL" class="ch.qos.logback.classic.net.SMTPAppender">
<SMTPHost>smtp.gmail.com</SMTPHost>
<SMTPPort>587</SMTPPort>
@@ -2440,7 +2480,7 @@
<root level="debug">
<appender-ref ref="EMAIL" />
</root>
-</configuration></p>
+</configuration></pre>
@@ -2736,7 +2776,7 @@
</p>
<em>Example 4.<span class="autoEx"/>: <code>DBAppender</code> configuration (logback-examples/src/main/java/chapter4/db/append-toMySQL-with-driverManager.xml)</em>
-<div class="source"><pre><configuration>
+<pre class="prettyprint source"><configuration>
<b><appender name="DB" class="ch.qos.logback.classic.db.DBAppender">
<connectionSource class="ch.qos.logback.core.db.DriverManagerConnectionSource">
@@ -2750,7 +2790,7 @@
<root level="debug" >
<appender-ref ref="DB" />
</root>
-</configuration></pre></div>
+</configuration></pre>
<p>
The correct driver must be declared. Here, the <code>com.mysql.jdbc.Driver</code>
@@ -2786,13 +2826,13 @@
commons-dbcp </a> package from Apache:
</p>
-<div class="source"><pre>
+<pre class="prettyprint source">
<connectionSource
class="ch.qos.logback.core.db.DriverManagerConnectionSource">
<param name="driver" value="org.apache.commons.dbcp.PoolingDriver"/>
<param name="url" value="jdbc:apache:commons:dbcp:/myPoolingDriver"/>
</connectionSource>
-</pre></div>
+</pre>
<p>
Then the configuration information for the commons-dbcp
@@ -2814,7 +2854,7 @@
</p>
<em>Example 4.<span class="autoEx"/>: <code>DBAppender</code> configuration (logback-examples/src/main/java/chapter4/db/append-with-datasource.xml)</em>
-<div class="source"><pre><configuration>
+<pre class="prettyprint source"><configuration>
<appender name="DB" class="ch.qos.logback.classic.db.DBAppender">
<b><connectionSource class="ch.qos.logback.core.db.DataSourceConnectionSource">
@@ -2837,7 +2877,7 @@
<root level="debug">
<appender-ref ref="DB" />
</root>
-</configuration></pre></div>
+</configuration></pre>
<p>
Not that in this configuration sample, we make heavy use of substitution variables.
@@ -2894,11 +2934,11 @@
application server provides.
</p>
-<div class="source"><pre><connectionSource class="ch.qos.logback.core.db.JNDIConnectionSource">
+<pre class="prettyprint source"><connectionSource class="ch.qos.logback.core.db.JNDIConnectionSource">
<param name="jndiLocation" value="jdbc/MySQLDS" />
<param name="username" value="myUser" />
<param name="password" value="myPassword" />
-</connectionSource></pre></div>
+</connectionSource></pre>
<p>
Note that this class will obtain an
@@ -2927,7 +2967,7 @@
</p>
<em>Example 4.<span class="autoEx"/> <code>DBAppender</code> configuration without pooling (logback-examples/src/main/java/chapter4/db/append-toMySQL-with-datasource.xml)</em>
- <p class="source"><configuration>
+ <pre class="prettyprint source"><configuration>
<appender name="DB" class="ch.qos.logback.classic.db.DBAppender">
<connectionSource class="ch.qos.logback.core.db.DataSourceConnectionSource">
@@ -2944,7 +2984,7 @@
<root level="debug">
<appender-ref ref="DB" />
</root>
-</configuration</p>
+</configuration</pre>
<p>With this configuration file, sending 500 logging events to a
MySQL database takes a whopping 5 seconds, that is 10 milliseconds
@@ -2960,7 +3000,7 @@
</p>
<em>Example 4.<span class="autoEx"/>: <code>DBAppender</code> configuration with pooling (logback-examples/src/main/java/chapter4/db/append-toMySQL-with-datasource-and-pooling.xml)</em>
- <p class="source"><configuration>
+ <pre class="prettyprint source"><configuration>
<appender name="DB" class="ch.qos.logback.classic.db.DBAppender">
<connectionSource
@@ -2978,7 +3018,7 @@
<root level="debug">
<appender-ref ref="DB" />
</root>
-</configuration></p>
+</configuration></pre>
<p>With this new configuration, sending 500 logging requests to
the same MySQL database as previously used takes around 0.5
@@ -3095,7 +3135,7 @@
</p>
<em>Example 4.<span class="autoEx"/>: <code>SyslogAppender</code> configuration (logback-examples/src/main/java/chapter4/conf/logback-syslog.xml)</em>
-<div class="source"><pre><configuration>
+<pre class="prettyprint source"><configuration>
<appender name="SYSLOG"
class="ch.qos.logback.classic.net.SyslogAppender">
@@ -3107,7 +3147,7 @@
<root level="debug">
<appender-ref ref="STDOUT" />
</root>
-</configuration></pre></div>
+</configuration></pre>
<p>When testing this configuration, you should verify that the
remote syslog daemon accepts requests from an external
@@ -3155,7 +3195,7 @@
configuration
(logback-examples/src/main/java/chapter4/sift/byUserid.xml)</em>
- <p class="source"><configuration>
+ <pre class="prettyprint source"><configuration>
<b><appender name="SIFT" class="ch.qos.logback.classic.sift.SiftingAppender"></b>
<!-- in the absence of the class attribute, it is assumed that the
@@ -3179,7 +3219,7 @@
<root level="DEBUG">
<appender-ref ref="SIFT" />
</root>
-</configuration></p>
+</configuration></pre>
<p>In the absence of a class attribute, it is assumed that the
@@ -3239,7 +3279,7 @@
<em>Example 4.<span class="autoExec"/>:
<code>CountingConsoleAppender</code>
(logback-examples/src/main/java/chapter4/CountingConsoleAppender.java)</em>
- <p class="source">package chapter4;
+ <pre class="prettyprint source">package chapter4;
import ch.qos.logback.core.AppenderBase;
import ch.qos.logback.core.Layout;
@@ -3284,7 +3324,7 @@
counter++;
}
-}</p>
+}</pre>
<p>The <code>start()</code> method checks for the presence of a
<code>Layout</code>. In case the layout is not set, the appender
@@ -3363,7 +3403,7 @@
Here is a sample configuration of a <code>SMTPAppender</code> in the access environment.
</p>
<em>Example 4.<span class="autoEx"/>: <code>SMTPAppender</code> configuration (logback-examples/src/main/java/chapter4/conf/access/logback-smtp.xml)</em>
-<div class="source"><pre><appender name="SMTP"
+<pre class="prettyprint source"><appender name="SMTP"
class="ch.qos.logback.access.net.SMTPAppender">
<layout class="ch.qos.logback.access.html.HTMLLayout">
<Pattern>%h%l%u%t%r%s%b</Pattern>
@@ -3376,7 +3416,7 @@
<From>sender_email(a)host.com</From>
<SMTPHost>mail.domain.com</SMTPHost>
<To>recipient_email(a)host.com</To>
-</appender></pre></div>
+</appender></pre>
<p>
This way of triggering the email lets user select pages that are important steps
@@ -3532,7 +3572,7 @@
</p>
<em>Example 4.<span class="autoEx"/>: DBAppender configuration (logback-examples/src/main/java/chapter4/conf/access/logback-DB.xml)</em>
- <p class="source"><configuration>
+ <pre class="prettyprint source"><configuration>
<appender name="DB" class="ch.qos.logback.access.db.DBAppender">
<connectionSource class="ch.qos.logback.core.db.DriverManagerConnectionSource">
@@ -3545,7 +3585,7 @@
</appender>
<appender-ref ref="DB" />
-</configuration></p>
+</configuration></pre>
<h3><a name="AccessSiftingAppender"
@@ -3572,7 +3612,7 @@
<em>Example 4.<span class="autoEx"/>: SiftingAppender configuration (logback-examples/src/main/java/chapter4/conf/sift/access-siftingFile.xml)</em>
- <p class="source"><configuration>
+ <pre class="prettyprint source"><configuration>
<appender name="SIFTING" class="ch.qos.logback.access.sift.SiftingAppender">
<Discriminator class="ch.qos.logback.access.sift.AccessEventDiscriminator">
<Key>id</Key>
@@ -3590,7 +3630,7 @@
</sift>
</appender>
<appender-ref ref="SIFTING" />
-</configuration></p>
+</configuration></pre>
<p>In the above configuration file, a <code>SiftingAppender</code>
Modified: logback/trunk/logback-site/src/site/pages/manual/architecture.html
==============================================================================
--- logback/trunk/logback-site/src/site/pages/manual/architecture.html (original)
+++ logback/trunk/logback-site/src/site/pages/manual/architecture.html Sat Aug 8 17:28:39 2009
@@ -8,12 +8,11 @@
<link rel="stylesheet" type="text/css" href="../css/common.css" />
<link rel="stylesheet" type="text/css" href="../css/screen.css" media="screen" />
<link rel="stylesheet" type="text/css" href="../css/_print.css" media="print" />
-
+ <link rel="stylesheet" type="text/css" href="../css/prettify.css" media="screen" />
</head>
- <body>
- <script type="text/javascript">
- prefix='../';
- </script>
+ <body onload="prettyPrint()">
+ <script type="text/javascript">prefix='../';</script>
+ <script type="text/javascript" src="../js/prettify.js"></script>
<script src="../templates/header.js" type="text/javascript"></script>
<div id="left">
<noscript>Please turn on Javascript to view this menu</noscript>
@@ -125,8 +124,8 @@
follows:
</p>
- <p class="source">Logger rootLogger = LoggerFactory.getLogger(<a
- href="http://www.slf4j.org/apidocs/constant-values.html#org.slf4j.Logger.ROOT_LOG…">org.slf4j.Logger.ROOT_LOGGER_NAME</a>);</p>
+ <pre class="prettyprint source">Logger rootLogger = LoggerFactory.getLogger(<a
+ href="http://www.slf4j.org/apidocs/constant-values.html#org.slf4j.Logger.ROOT_LOG…">org.slf4j.Logger.ROOT_LOGGER_NAME</a>);</pre>
<p>All other loggers are also retrieved with the class static
<code>getLogger</code> method found in the <a
@@ -136,7 +135,7 @@
interface are listed below.
</p>
- <p class="source">package org.slf4j;
+ <pre class="prettyprint source">package org.slf4j;
public interface Logger {
// Printing methods:
@@ -145,7 +144,7 @@
public void info(String message);
public void warn(String message);
public void error(String message);
-}</p>
+}</pre>
<p>Loggers may be assigned levels. The set of possible levels,
that is TRACE, DEBUG, INFO, WARN and ERROR are defined in the
@@ -431,7 +430,7 @@
<p>Here is an example of the basic selection rule.</p>
- <div class="source"><pre>// get a logger instance named "com.foo"
+ <pre class="prettyprint source">// get a logger instance named "com.foo"
Logger logger = LoggerFactory.getLogger("com.foo");
//set its Level to <span class="blue">INFO</span>
logger.setLevel(Level. <span class="blue">INFO</span>);
@@ -450,7 +449,7 @@
barlogger.<span class="green bold">info</span>("Located nearest gas station.");
// This request is disabled, because <span class="green bold">DEBUG</span> < <span class="blue">INFO</span>.
-barlogger.<span class="green bold">debug</span>("Exiting gas station search");</pre></div>
+barlogger.<span class="green bold">debug</span>("Exiting gas station search");</pre>
<a name="RetrievingLoggers"></a>
<h3>Retrieving Loggers</h3>
@@ -461,8 +460,8 @@
</p>
<p>For example, in</p>
- <div class="source"><pre>Logger x = LoggerFactory.getLogger("wombat");
-Logger y = LoggerFactory.getLogger("wombat");</pre></div>
+ <pre class="prettyprint source">Logger x = LoggerFactory.getLogger("wombat");
+Logger y = LoggerFactory.getLogger("wombat");</pre>
<p>
<code>x</code> and <code>y</code> refer to
@@ -634,7 +633,7 @@
something akin to:
</p>
- <div class="source"><pre>176 [main] DEBUG chapter2.HelloWorld2 - Hello world.</pre></div>
+ <div class="prettyprint source"><pre>176 [main] DEBUG chapter2.HelloWorld2 - Hello world.</pre></div>
<p>The first field is the number of milliseconds elapsed since the
start of the program. The second field is the thread making the
@@ -656,7 +655,7 @@
<p>For some Logger <code>logger</code>, writing,</p>
- <div class="source"><pre>logger.debug("Entry number: " + i + " is " + String.valueOf(entry[i]));</pre></div>
+ <pre class="prettyprint source">logger.debug("Entry number: " + i + " is " + String.valueOf(entry[i]));</pre>
<p>incurs the cost of constructing the message parameter, that is
converting both integer <code>i</code> and <code>entry[i]</code>
@@ -668,9 +667,9 @@
by surrounding the log statement with a test. Here is an example.
</p>
- <div class="source"><pre>if(logger.isDebugEnabled()) {
+ <pre class="prettyprint source">if(logger.isDebugEnabled()) {
logger.debug("Entry number: " + i + " is " + String.valueOf(entry[i]));
-}</pre></div>
+}</pre>
<p>This way you will not incur the cost of parameter construction
@@ -690,8 +689,8 @@
</p>
- <div class="source"><pre>Object entry = new SomeObject();
-logger.debug("The entry is {}.", entry);</pre></div>
+ <pre class="prettyprint source">Object entry = new SomeObject();
+logger.debug("The entry is {}.", entry);</pre>
<p>After evaluting whether to log or not, and only if the decision
is positive, will the logger implementation format the message and
@@ -707,15 +706,15 @@
least 30.
</p>
- <div class="source"><pre>logger.debug("The new entry is "+entry+".");
-logger.debug("The new entry is {}.", entry);</pre></div>
+ <pre class="prettyprint source">logger.debug("The new entry is "+entry+".");
+logger.debug("The new entry is {}.", entry);</pre>
<p>A two argument variant is also availalble. For example, you can
write:
</p>
- <div class="source"><pre>logger.debug("The new entry is {}. It replaces {}.", entry, oldEntry);</pre></div>
+ <pre class="prettyprint source">logger.debug("The new entry is {}. It replaces {}.", entry, oldEntry);</pre>
<p>If three or more arguments need to be passed, an
<code>Object[]</code> variant is also availalble. For example, you
@@ -723,8 +722,8 @@
</p>
- <div class="source"><pre>Object[] paramArray = {newVal, below, above};
-logger.debug("Value {} was inserted between {} and {}.", paramArray);</pre></div>
+ <pre class="prettyprint source">Object[] paramArray = {newVal, below, above};
+logger.debug("Value {} was inserted between {} and {}.", paramArray);</pre>
<a name="UnderTheHood"></a>
@@ -845,7 +844,7 @@
For example, for some logger <em>x</em> writing,
</p>
- <div class="source"><pre>x.debug("Entry number: " + i + "is " + entry[i]);</pre></div>
+ <pre class="prettyprint source">x.debug("Entry number: " + i + "is " + entry[i]);</pre>
<p>
incurs the cost of constructing the message parameter, i.e. converting both
@@ -859,7 +858,7 @@
logging:
</p>
- <div class="source"><pre>x.debug("Entry number: {} is {}", i, entry[i]);</pre></div>
+ <pre class="prettyprint source">x.debug("Entry number: {} is {}", i, entry[i]);</pre>
<p>
This variant will not incur the cost of parameter
Modified: logback/trunk/logback-site/src/site/pages/manual/filters.html
==============================================================================
--- logback/trunk/logback-site/src/site/pages/manual/filters.html (original)
+++ logback/trunk/logback-site/src/site/pages/manual/filters.html Sat Aug 8 17:28:39 2009
@@ -8,11 +8,12 @@
<link rel="stylesheet" type="text/css" href="../css/common.css" />
<link rel="stylesheet" type="text/css" href="../css/screen.css" media="screen" />
<link rel="stylesheet" type="text/css" href="../css/_print.css" media="print" />
-
+ <link rel="stylesheet" type="text/css" href="../css/prettify.css" media="screen" />
</head>
- <body>
+ <body onload="prettyPrint()">
<script type="text/javascript">prefix='../';</script>
+ <script type="text/javascript" src="../js/prettify.js"></script>
<script src="../templates/header.js" type="text/javascript"></script>
<div id="left">
<noscript>Please turn on Javascript to view this menu</noscript>
@@ -116,7 +117,7 @@
</p>
<em>Example 6.1: Basic custom filter (<a href="../xref/chapter6/SampleFilter.html">logback-examples/src/main/java/chapter6/SampleFilter.java</a>)</em>
-<div class="source"><pre>package chapter6;
+<pre class="prettyprint source">package chapter6;
import ch.qos.logback.classic.spi.LoggingEvent;
import ch.qos.logback.core.filter.Filter;
@@ -134,7 +135,7 @@
return FilterReply.NEUTRAL;
}
}
-}</pre></div>
+}</pre>
<p>
What is shown above might be the simplest filter. Like any filter, it
@@ -143,7 +144,7 @@
</p>
<em>Example 6.2: SampleFilter configuration (logback-examples/src/main/java/chapter6/SampleFilterConfig.xml)</em>
-<div class="source"><pre><configuration>
+<pre class="prettyprint source"><configuration>
<appender name="STDOUT"
class="ch.qos.logback.core.ConsoleAppender">
<b><Filter class="chapter6.SampleFilter" /></b>
@@ -158,7 +159,7 @@
<root>
<appender-ref ref="STDOUT" />
</root>
-</configuration></pre></div>
+</configuration></pre>
<p>Thanks to Joran, logback's powerful configuration framework,
adding an option to such a filter is very easy. Just add the
@@ -191,7 +192,7 @@
</p>
<em>Example 6.3: Sample LevelFilter configuration (logback-examples/src/main/java/chapter6/levelFilterConfig.xml)</em>
-<div class="source"><pre><configuration>
+<pre class="prettyprint source"><configuration>
<appender name="CONSOLE"
class="ch.qos.logback.core.ConsoleAppender">
<b><filter class="ch.qos.logback.classic.filter.LevelFilter">
@@ -208,7 +209,7 @@
<root level="DEBUG">
<appender-ref ref="CONSOLE" />
</root>
-</configuration></pre></div>
+</configuration></pre>
<p>
The second filter that ships with logback is
@@ -220,7 +221,7 @@
</p>
<em>Example 6.4: Sample ThresholdFilter configuration (logback-examples/src/main/java/chapter6/thresholdFilterConfig.xml)</em>
-<div class="source"><pre><configuration>
+<pre class="prettyprint source"><configuration>
<appender name="CONSOLE"
class="ch.qos.logback.core.ConsoleAppender">
<b><filter class="ch.qos.logback.classic.filter.ThresholdFilter">
@@ -235,7 +236,7 @@
<root level="DEBUG">
<appender-ref ref="CONSOLE" />
</root>
-</configuration></pre></div>
+</configuration></pre>
<h3>Evaluator Filters taking Java Expressions</h3>
@@ -350,7 +351,7 @@
<em>Example 6.5: Basic event evaluator usage (logback-examples/src/main/java/chapter6/basicEventEvaluator.xml)</em>
-<div class="source"><pre><configuration>
+<pre class="prettyprint source"><configuration>
<appender name="STDOUT"
class="ch.qos.logback.core.ConsoleAppender">
@@ -371,7 +372,7 @@
<root level="INFO">
<appender-ref ref="STDOUT" />
</root>
-</configuration></pre></div>
+</configuration></pre>
<p>The bold part in the previous configuration adds an
<code>EvaluatorFilter</code> to a <code>ConsoleAppender</code>. An
@@ -472,7 +473,7 @@
</p>
<em>Example 6.6: Basic custom <code>TurboFilter</code> (<a href="../xref/chapter6/SampleTurboFilter.html">logback-examples/src/main/java/chapter6/SampleTurboFilter.java</a>)</em>
-<div class="source"><pre>package chapter6;
+<pre class="prettyprint source">package chapter6;
import org.slf4j.Marker;
import org.slf4j.MarkerFactory;
@@ -518,7 +519,7 @@
}
}
}
-</pre></div>
+</pre>
<p>The <code>TurboFilter</code> above accepts events that contain
a specific marker. If said marker is not found, then the filter
@@ -537,7 +538,7 @@
</p>
<em>Example 6.7: Basic custom <code>TurboFilter</code> configuration (logback-examples/src/main/java/chapter6/sampleTurboFilterConfig.xml)</em>
-<div class="source"><pre><configuration>
+<pre class="prettyprint source"><configuration>
<b><turboFilter class="chapter6.SampleTurboFilter">
<Marker>sample</Marker>
</turboFilter></b>
@@ -554,7 +555,7 @@
<root>
<appender-ref ref="STDOUT" />
</root>
-</configuration></pre></div>
+</configuration></pre>
<p>Logback classic ships with several <code>TurboFilter</code>
classes ready for use. The <a
@@ -574,7 +575,7 @@
<em>Example 6.8: <code>MDCFilter</code> and <code>MarkerFilter</code>
configuration (logback-examples/src/main/java/chapter6/turboFilters.xml)</em>
-<div class="source"><pre><configuration>
+<pre class="prettyprint source"><configuration>
<turboFilter class="ch.qos.logback.classic.turbo.MDCFilter">
<MDCKey>username</MDCKey>
@@ -596,7 +597,7 @@
<root level="info">
<appender-ref ref="console" />
</root>
-</configuration></pre></div>
+</configuration></pre>
<p>You can see this configuration in action by issuing the
following command:
@@ -664,8 +665,8 @@
write:
</p>
- <p class="source">logger.debug("Hello "+name0);
-logger.debug("Hello "+name1);</p>
+ <pre class="prettyprint source">logger.debug("Hello "+name0);
+logger.debug("Hello "+name1);</pre>
<p>Assuming <code>name0</code> and <code>name1</code> have
different values, the two "Hello" messages will be considered as
@@ -680,8 +681,8 @@
thus considered as repetitions.
</p>
- <p class="source">logger.debug("Hello {}.", name0);
-logger.debug("Hello {}.", name1);</p>
+ <pre class="prettyprint source">logger.debug("Hello {}.", name0);
+logger.debug("Hello {}.", name1);</pre>
<p>The number of allowed repetitions can be specified by the <span
class="option">AllowedRepetitions</span> property. For example, if
@@ -701,7 +702,7 @@
<em>Example: <code>DuplicateMessageFilter</code>
configuration (logback-examples/src/main/java/chapter6/duplicateMessage.xml)</em>
-<div class="source"><pre><configuration>
+<pre class="prettyprint source"><configuration>
<b><turboFilter class="ch.qos.logback.classic.turbo.DuplicateMessageFilter"/></b>
@@ -714,7 +715,7 @@
<root level="info">
<appender-ref ref="console" />
</root>
-</configuration></pre></div>
+</configuration></pre>
<p>Thus, the output for <code>FilterEvents</code> application
configured with <em>duplicateMessage.xml</em> is:
@@ -775,7 +776,7 @@
</p>
<em>Example 6.9: Access Evaluator (logback-examples/src/main/java/chapter6/accessEventEvaluator.xml)</em>
-<div class="source"><pre><configuration>
+<pre class="prettyprint source"><configuration>
<appender name="STDOUT"
class="ch.qos.logback.core.ConsoleAppender">
@@ -794,7 +795,7 @@
</appender>
<appender-ref ref="STDOUT" />
-</configuration></pre></div>
+</configuration></pre>
<p>We might imagine a slightly more complex use of filters to
ensure logging of 404 errors, except those returned on access to
@@ -802,7 +803,7 @@
</p>
<em>Example 6.10: Access Evaluator (logback-examples/src/main/java/chapter6/accessEventEvaluator2.xml)</em>
- <p class="source"><configuration>
+ <pre class="prettyprint source"><configuration>
<appender name="STDOUT"
class="ch.qos.logback.core.ConsoleAppender">
@@ -829,7 +830,7 @@
<appender-ref ref="STDOUT" />
</configuration>
- </p>
+ </pre>
<script src="../templates/footer.js" type="text/javascript"></script>
Modified: logback/trunk/logback-site/src/site/pages/manual/introduction.html
==============================================================================
--- logback/trunk/logback-site/src/site/pages/manual/introduction.html (original)
+++ logback/trunk/logback-site/src/site/pages/manual/introduction.html Sat Aug 8 17:28:39 2009
@@ -7,11 +7,12 @@
<link rel="stylesheet" type="text/css" href="../css/common.css" />
<link rel="stylesheet" type="text/css" href="../css/screen.css" media="screen" />
<link rel="stylesheet" type="text/css" href="../css/_print.css" media="print" />
-
+ <link rel="stylesheet" type="text/css" href="../css/prettify.css" media="screen" />
</head>
- <body>
+ <body onload="prettyPrint()">
<script type="text/javascript">prefix='../';</script>
+ <script type="text/javascript" src="../js/prettify.js"></script>
<script src="../templates/header.js" type="text/javascript"> </script>
<div id="left">
<noscript>Please turn on Javascript to view this menu</noscript>
@@ -78,7 +79,7 @@
<p>Let us now begin experimenting with logback.</p>
<em>Example 1.1: Basic template for logging (<a href="../xref/chapter1/HelloWorld1.html">logback-examples/src/main/java/chapter1/HelloWorld1.java</a>)</em>
-<div class="source"><pre>package chapter1;
+<pre class="prettyprint source">package chapter1;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -91,7 +92,7 @@
logger.debug("Hello world.");
}
-}</pre></div>
+}</pre>
<p><code>HelloWorld</code> class is defined in the
<code>chapter1</code> package. It starts by importing the <a
@@ -133,7 +134,7 @@
logger.
</p>
-<div class="source"><pre>20:49:07.962 [main] DEBUG chapter1.HelloWorld1 - Hello world.</pre></div>
+ <p class="source">20:49:07.962 [main] DEBUG chapter1.HelloWorld1 - Hello world.</p>
<p>Logback can report information about its internal state using a
built-in status system. Important events occuring during logback's
@@ -144,7 +145,7 @@
</p>
<em>Example 1.2: Printing Logger Status (<a href="../xref/chapter1/HelloWorld2.html">logback-examples/src/main/java/chapter1/HelloWorld2.java</a>)</em>
-<div class="source"><pre>package chapter1;
+<pre class="prettyprint source">package chapter1;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -161,7 +162,7 @@
<b>LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory();
StatusPrinter.print(lc);</b>
}
-}</pre></div>
+}</pre>
<p>Running the <code>HelloWorld2</code> application will produce
@@ -237,8 +238,9 @@
-->
- <p>Logback relies on <a href="http://maven.apache.org">Maven2</a> as
- its build tool. Maven2 is a widely-used open-source build tool.
+ <p>As its build tool, logback relies on <a
+ href="http://maven.apache.org">Maven2</a>, a widely-used open-source
+ build tool.
</p>
<p>Once you have installed Maven2, building the logback project,
Modified: logback/trunk/logback-site/src/site/pages/manual/jmxConfig.html
==============================================================================
--- logback/trunk/logback-site/src/site/pages/manual/jmxConfig.html (original)
+++ logback/trunk/logback-site/src/site/pages/manual/jmxConfig.html Sat Aug 8 17:28:39 2009
@@ -8,11 +8,13 @@
<link rel="stylesheet" type="text/css" href="../css/common.css" />
<link rel="stylesheet" type="text/css" href="../css/screen.css" media="screen" />
<link rel="stylesheet" type="text/css" href="../css/_print.css" media="print" />
+ <link rel="stylesheet" type="text/css" href="../css/prettify.css" media="screen" />
<title>JMX Configuration</title>
</head>
- <body>
+ <body onload="prettyPrint()">
<script type="text/javascript">prefix='../';</script>
+ <script type="text/javascript" src="../js/prettify.js"></script>
<script src="../templates/header.js" type="text/javascript"></script>
<div id="left">
<noscript>Please turn on Javascript to view this menu</noscript>
@@ -45,9 +47,9 @@
your logback configuration file, as shown below:
</p>
- <p class="source"><configuration>
+ <pre class="prettyprint source"><configuration>
<b><jmxConfigurator /></b>
-
+
<appender name="console" class="ch.qos.logback.classic.ConsoleAppender">
<layout class="ch.qos.logback.classic.PatternLayout">
<Pattern>%date [%thread] %-5level %logger{25} - %msg%n</Pattern>
@@ -57,7 +59,7 @@
<root level="debug"/>
<appender-ref ref="console" />
</root>
-</configuration></p>
+</configuration></pre>
<p>After you connect to your server with <em>jconsole</em>, on the
MBeans panel, under "ch.qos.logback.classic.jmx.Configurator"
@@ -114,7 +116,7 @@
<code>javax.servlet.ServletContextListener</code>. Here is sample
code:</p>
- <p class="source">import javax.servlet.ServletContextEvent;
+ <pre class="prettyprint source">import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import org.slf4j.LoggerFactory;
@@ -129,7 +131,7 @@
public void contextInitialized(ServletContextEvent sce) {
}
-} </p>
+} </pre>
<!-- ============ Multiple web-applications ================== -->
@@ -212,7 +214,7 @@
are the elements that need to be added:
</p>
- <p class="source"><Call id="MBeanServer" class="java.lang.management.ManagementFactory"
+ <pre class="prettyprint source"><Call id="MBeanServer" class="java.lang.management.ManagementFactory"
name="getPlatformMBeanServer"/>
<Get id="Container" name="container">
@@ -224,7 +226,7 @@
</New>
</Arg>
</Call>
-</Get> </p>
+</Get> </pre>
<p>If you wish to access the MBeans exposed by Jetty via the
<code>jconsole</code> application, then you need start jetty after
@@ -264,7 +266,7 @@
an instruction to set the management port.
</p>
- <p class="source"><Call id="MBeanServer"
+ <pre class="prettyprint source"><Call id="MBeanServer"
class="java.lang.management.ManagementFactory"
name="getPlatformMBeanServer"/>
@@ -279,7 +281,7 @@
</Arg>
</Call>
</Get>
- </p>
+ </pre>
<p>Moreover, <em>mx4j-tools.jar</em> needs to be added to Jetty's
class path.
@@ -288,7 +290,7 @@
<p>If you are running jetty as a Maven plug-in, then you need to add
<em>mx4j-tools</em> as a dependency.</p>
- <p class="source"><plugin>
+ <pre class="prettyprint source"><plugin>
<groupId>org.mortbay.jetty</groupId>
<artifactId>maven-jetty-plugin</artifactId>
<configuration>
@@ -302,7 +304,7 @@
<version>3.0.1</version>
</dependency>
</dependencies></b>
-</plugin></p>
+</plugin></pre>
<p>After Jetty is started with the above configuration,
<code>JMXConfigurator</code> will be available at the following
@@ -368,12 +370,12 @@
</p>
- <p class="source"><Connector port="0"
+ <pre class="prettyprint source"><Connector port="0"
handler.list="mx"
mx.enabled="true"
mx.httpHost="localhost"
mx.httpPort="8082"
- protocol="AJP/1.3" /></p>
+ protocol="AJP/1.3" /></pre>
<p>Once Tomcat is started, you should be able to find
JMXConfigurator by pointing your browser at the following URL
Modified: logback/trunk/logback-site/src/site/pages/manual/layouts.html
==============================================================================
--- logback/trunk/logback-site/src/site/pages/manual/layouts.html (original)
+++ logback/trunk/logback-site/src/site/pages/manual/layouts.html Sat Aug 8 17:28:39 2009
@@ -8,11 +8,12 @@
<link rel="stylesheet" type="text/css" href="../css/common.css" />
<link rel="stylesheet" type="text/css" href="../css/screen.css" media="screen" />
<link rel="stylesheet" type="text/css" href="../css/_print.css" media="print" />
-
+ <link rel="stylesheet" type="text/css" href="../css/prettify.css" media="screen" />
</head>
-<body>
+<body onload="prettyPrint()">
<script type="text/javascript">prefix='../';</script>
+ <script type="text/javascript" src="../js/prettify.js"></script>
<script src="../templates/header.js" type="text/javascript"></script>
<div id="left">
<noscript>Please turn on Javascript to view this menu</noscript>
@@ -49,13 +50,13 @@
interface is shown below.
</p>
- <div class="source">public interface Layout<E> extends ContextAware, LifeCycle {
+ <pre class="prettyprint source">public interface Layout<E> extends ContextAware, LifeCycle {
String doLayout(E event);
String getHeader();
String getFooter();
String getContentType();
-}</div>
+}</pre>
<p>This interface is rather simple and yet is sufficent for many
formatting needs. The Texan developer from Texas, who you might
@@ -90,7 +91,7 @@
<a href="../xref/chapter5/MySampleLayout.html">
(logback-examples/src/main/java/chapter5/MySampleLayout.java)</a></em>
- <div class="source"><pre>package chapter5;
+ <pre class="prettyprint source">package chapter5;
import ch.qos.logback.classic.spi.ILoggingEvent;
import ch.qos.logback.core.LayoutBase;
@@ -111,7 +112,7 @@
sbuf.append(CoreConstants.LINE_SEP);
return sbuf.toString();
}
-}</pre></div>
+}</pre>
<p>Note that <code>MySampleLayout</code> extends <a
href="../xref/ch/qos/logback/core/LayoutBase.html">
@@ -152,7 +153,7 @@
<em>Example 5.0: Configuration of MySampleLayout
(logback-examples/src/main/java/chapter5/sampleLayoutConfig.xml)</em>
-<div class="source"><pre><configuration>
+<pre class="prettyprint source"><configuration>
<appender name="STDOUT"
class="ch.qos.logback.core.ConsoleAppender">
@@ -162,7 +163,7 @@
<root level="debug">
<appender-ref ref="STDOUT" />
</root>
-</configuration></pre></div>
+</configuration></pre>
<p>The sample application <a href="../xref/chapter5/SampleLogging.html">
<code>chapter5.SampleLogging</code></a> configures logback with the
@@ -201,7 +202,7 @@
</p>
<p>Here is the implementation of this class:</p>
- <p class="source">package chapter5;
+ <pre class="prettyprint source">package chapter5;
import ch.qos.logback.classic.spi.ILoggingEvent;
import ch.qos.logback.core.LayoutBase;
@@ -240,7 +241,7 @@
sbuf.append(LINE_SEP);
return sbuf.toString();
}
-}</p>
+}</pre>
<p>The addition of the corresponding setter method is all that is
@@ -253,7 +254,7 @@
</p>
- <p class="source"><configuration>
+ <pre class="prettyprint source"><configuration>
<appender name="STDOUT"
class="ch.qos.logback.core.ConsoleAppender">
@@ -266,7 +267,7 @@
<root level="debug">
<appender-ref ref="STDOUT" />
</root>
-</configuration></p>
+</configuration></pre>
<p></p>
@@ -302,7 +303,7 @@
<a href="../xref/chapter5/PatternSample.html">
(logback-examples/src/main/java/chapter5/PatternSample.java)</a>
</em>
- <div class="source"><pre>package chapter5;
+ <pre class="prettyprint source">package chapter5;
import org.slf4j.LoggerFactory;
@@ -328,7 +329,7 @@
rootLogger.debug("Message 1");
rootLogger.warn("Message 2");
}
-}</pre></div>
+}</pre>
<p>The conversion pattern is set to be <b>"%-5level [%thread]:
%message%n"</b>. Running PatternSample will yield the following
@@ -1140,13 +1141,13 @@
which will be covered soon, may add evaluator names to the option
list, as shown below:</p>
- <div class="source"><pre>
+ <pre class="prettyprint source">
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<layout class="ch.qos.logback.classic.PatternLayout">
<param name="Pattern" value="%-4relative [%thread] %-5level - %msg%n \
<b>%caller{2, DISP_CALLER_EVAL, OTHER_EVAL_NAME, THIRD_EVAL_NAME}</b>" />
</layout>
- </appender></pre></div>
+ </appender></pre>
<h3>Evaluators</h3>
@@ -1177,7 +1178,7 @@
Example 5.2: Sample usage of EventEvaluators
(logback-examples/src/main/java/chapter5/callerEvaluatorConfig.xml)
</em>
- <p class="source"><configuration>
+ <pre class="prettyprint source"><configuration>
<b><evaluator name="DISP_CALLER_EVAL">
<Expression>logger.getName().contains("chapter5") &amp;&amp; \
message.contains("who calls thee")</Expression>
@@ -1193,7 +1194,7 @@
<root level="debug">
<appender-ref ref="STDOUT" />
</root>
-</configuration></p>
+</configuration></pre>
<p>Due to XML encoding rules, the & character cannot be
written as is, and needs to be escaped as &amp;.</p>
@@ -1207,7 +1208,7 @@
(logback-examples/src/main/java/chapter5/CallerEvaluatorExample.java)</a>
</em>
</p>
- <p class="source">package chapter5;
+ <pre class="prettyprint source">package chapter5;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -1239,7 +1240,7 @@
}
}
}
-}</p>
+}</pre>
<p>
The <em>CallerEvaluatorExample</em> application does nothing particularly
fancy. Five logging requests are issued, the third one being
@@ -1293,7 +1294,7 @@
(logback-examples/src/main/java/chapter5/ExceptionEvaluatorExample.java)</a>
</em>
</p>
-<div class="source"><pre>package chapter5;
+<pre class="prettyprint source">package chapter5;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -1325,7 +1326,7 @@
}
}
}
-}</pre></div>
+}</pre>
<p>The following configuration will supress the stack trace of the
third logging request.</p>
@@ -1333,7 +1334,7 @@
Example 5.3: Sample usage of EventEvaluators
(logback-examples/src/main/java/chapter5/exceptionEvaluatorConfig.xml)
</em>
- <div class="source"><pre><configuration>
+ <pre class="prettyprint source"><configuration>
<b><evaluator name="DISPLAY_EX_EVAL">
<Expression>throwable != null &amp;&amp; throwable instanceof \
@@ -1351,7 +1352,7 @@
<root level="debug">
<appender-ref ref="STDOUT" />
</root>
-</configuration></pre></div>
+</configuration></pre>
<p>With this configuration, each time an instance of the
<em>chapter5.TestException</em> is included within a logging
@@ -1390,7 +1391,7 @@
<em> Example 5.4: Sample Converter Example
<a href="../xref/chapter5/MySampleConverter.html">
(src/main/java/chapter5/MySampleConverter.java)</a></em>
-<div class="source"><pre>package chapter5;
+<pre class="prettyprint source">package chapter5;
import ch.qos.logback.classic.Level;
import ch.qos.logback.classic.pattern.ClassicConverter;
@@ -1427,7 +1428,7 @@
}
}
}
-</pre></div>
+</pre>
java chapter5.SampleLogging src/main/java/chapter5/mySampleConverterConfig.xml
@@ -1444,7 +1445,7 @@
new conversion word in the configuration file, as shown below:</p>
<em> Example 5.4: Sample Converter Example (src/main/java/chapter5/mySampleConverterConfig.xml)</em>
-<div class="source"><pre><configuration>
+<pre class="prettyprint source"><configuration>
<b><conversionRule conversionWord="sample" converterClass="chapter5.MySampleConverter" /></b>
@@ -1458,7 +1459,7 @@
<root level="debug">
<appender-ref ref="STDOUT" />
</root>
-</configuration></pre></div>
+</configuration></pre>
<p>In this configuration file, once the new conversion word has
been declared, we can refert to it within a
@@ -1526,7 +1527,7 @@
the use of <code>HTMLLayout</code>.
</p>
-<div class="source"><configuration debug="true">
+<pre class="prettyprint source"><configuration debug="true">
<appender name="FILE" class="ch.qos.logback.core.FileAppender">
<layout class="ch.qos.logback.classic.html.HTMLLayout">
<b><pattern>%relative%thread%mdc%level%logger%msg</pattern></b>
@@ -1538,12 +1539,12 @@
<appender-ref ref="FILE" />
</root>
</configuration>
-</div>
+</pre>
<p>Launching the <code>TrivialMain</code> application listed below
will create the file <em>test.html</em> on your local drive.</p>
- <p class="source">import org.slf4j.Logger;
+ <pre class="prettyprint source">import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class TrivialMain {
@@ -1558,7 +1559,7 @@
}
logger.error("Finish off with fireworks", new Exception("Just testing"));
}
-}</p>
+}</pre>
<p>The contents of <em>test.html</em> should be similar to:
</p>
@@ -1606,13 +1607,13 @@
<code><layout></code> element, as shown below.
</p>
-<div class="source"><pre><layout>
+<pre class="prettyprint source"><layout>
...
<cssBuilder class="ch.qos.logback.core.html.UrlCssBuilder">
<url>path_to_StyleFile.css</url>
</cssBuilder>
...
-</layout></pre></div>
+</layout></pre>
<p>The <code>HTMLLayout</code> is often used in conjunction with
@@ -1620,7 +1621,7 @@
formatted in HTML. Here is a typical configuration:
</p>
- <div class="source"><pre><configuration>
+ <pre class="prettyprint source"><configuration>
<appender name="SMTP" class="ch.qos.logback.classic.net.SMTPAppender">
<layout class="ch.qos.logback.classic.html.HTMLLayout">
<pattern>%relative%thread%mdc%level%class%msg</pattern>
@@ -1634,14 +1635,14 @@
<root level="debug">
<appender-ref ref="SMTP" />
</root>
-</configuration></pre></div>
+</configuration></pre>
<p><code>HTMLLayout</code> can also be used with any
<code>FileAppender</code>, including a a rolling file appender, as
shown in the sample configuration below.
</p>
- <p class="source"><configuration>
+ <pre class="prettyprint source"><configuration>
<appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<ActiveFileName>lastLogEntries.html</ActiveFileName>
@@ -1660,7 +1661,7 @@
<root level="debug">
<appender-ref ref="FILE" />
</root>
-</configuration></p>
+</configuration></pre>
<h3><a name="log4jXMLLayout" href="#log4jXMLLayout">Log4j XMLLayout</a></h3>
@@ -1690,7 +1691,7 @@
<p>Here is a sample configuration</p>
- <p class="source"><configuration>
+ <pre class="prettyprint source"><configuration>
<appender name="FILE" class="ch.qos.logback.core.FileAppender">
<File>test.xml</File>
<layout class="ch.qos.logback.classic.log4j.XMLLayout">
@@ -1701,7 +1702,7 @@
<root level="debug">
<appender-ref ref="FILE" />
</root>
-</configuration> </p>
+</configuration> </pre>
<h2>Logback access</h2>
Modified: logback/trunk/logback-site/src/site/pages/manual/loggingSeparation.html
==============================================================================
--- logback/trunk/logback-site/src/site/pages/manual/loggingSeparation.html (original)
+++ logback/trunk/logback-site/src/site/pages/manual/loggingSeparation.html Sat Aug 8 17:28:39 2009
@@ -8,10 +8,11 @@
<link rel="stylesheet" type="text/css" href="../css/common.css" />
<link rel="stylesheet" type="text/css" href="../css/screen.css" media="screen" />
<link rel="stylesheet" type="text/css" href="../css/_print.css" media="print" />
-
+ <link rel="stylesheet" type="text/css" href="../css/prettify.css" media="screen" />
</head>
- <body>
+ <body onload="prettyPrint()">
<script type="text/javascript">prefix='../';</script>
+ <script type="text/javascript" src="../js/prettify.js"></script>
<script src="../templates/header.js" type="text/javascript"></script>
<div id="left">
<noscript>Please turn on Javascript to view this menu</noscript>
@@ -91,10 +92,10 @@
referencing a logger is via a static reference. For example,
</p>
- <p class="source">public class Foo {
+ <pre class="prettyprint source">public class Foo {
<b>static</b> Logger logger = LoggerFactory.getLogger(Foo.class);
...
-}</p>
+}</pre>
<p>Static references are both memory and CPU efficient. Only one
logger reference is used for all instances of the class. Moreover,
@@ -127,7 +128,7 @@
contexts. When you write:
</p>
- <p class="source">Logger logger = LoggerFactory.getLogger("foo");</p>
+ <pre class="prettyprint source">Logger logger = LoggerFactory.getLogger("foo");</pre>
<p>the <code>getLogger</code>() method in
<code>LoggerFactory</code> class asks the SLF4J binding for a
@@ -190,11 +191,11 @@
file. If "kenobi" was the name of your application, you would add
the following XML element to kenobi's web.xml file:</p>
- <p class="source"><env-entry>
+ <pre class="prettyprint source"><env-entry>
<env-entry-name>logback/context-name</env-entry-name>
<env-entry-type>java.lang.String</env-entry-type>
<env-entry-value>kenobi</env-entry-value>
-</env-entry></p>
+</env-entry></pre>
<p>Assuming you have enabled <code>ContextJNDISelector</code>,
logging for Kenobi will be done using a logger context named
@@ -213,11 +214,11 @@
</p>
- <p class="source"><env-entry>
+ <pre class="prettyprint source"><env-entry>
<env-entry-name>logback/configuration-resource</env-entry-name>
<env-entry-type>java.lang.String</env-entry-type>
<env-entry-value>my_config.xml</env-entry-value>
-</env-entry></p>
+</env-entry></pre>
<h3>Configuring Tomcat for ContextJNDISelector</h3>
@@ -235,7 +236,7 @@
catalina.bat in Windows, found under <em>$TOMCAT_HOME/bin</em>
folder.</p>
- <p class="source">JAVA_OPTS="$JAVA_OPTS -Dlogback.ContextSelector=JNDI</p>
+ <p class="source">JAVA_OPTS="$JAVA_OPTS -Dlogback.ContextSelector=JNDI"</p>
<h3>Hot deploying applications</h3>
@@ -251,9 +252,9 @@
add the following lines to your web-applications <em>web.xml</em>
file.</p>
- <p class="source"><listener>
+ <pre class="prettyprint source"><listener>
<listener-class>ch.qos.logback.classic.selector.servlet.ContextDetachingSCL</listener-class>
-</listener></p>
+</listener></pre>
<h3>Better performance</h3>
@@ -267,14 +268,14 @@
be installed by adding the following lines to your applications
web.xml file.</p>
- <p class="source"><filter>
+ <pre class="prettyprint source"><filter>
<filter-name>LoggerContextFilter</filter-name>
<filter-class>ch.qos.logback.classic.selector.servlet.LoggerContextFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>LoggerContextFilter</filter-name>
<url-pattern>/*</url-pattern>
-</filter-mapping></p>
+</filter-mapping></pre>
<p>At the beginning of each http-request,
<code>LoggerContextFilter</code> will obtain the logger context
Modified: logback/trunk/logback-site/src/site/pages/manual/mdc.html
==============================================================================
--- logback/trunk/logback-site/src/site/pages/manual/mdc.html (original)
+++ logback/trunk/logback-site/src/site/pages/manual/mdc.html Sat Aug 8 17:28:39 2009
@@ -8,10 +8,11 @@
<link rel="stylesheet" type="text/css" href="../css/common.css" />
<link rel="stylesheet" type="text/css" href="../css/screen.css" media="screen" />
<link rel="stylesheet" type="text/css" href="../css/_print.css" media="print" />
-
+ <link rel="stylesheet" type="text/css" href="../css/prettify.css" media="screen" />
</head>
- <body>
+ <body onload="prettyPrint()">
<script type="text/javascript">prefix='../';</script>
+ <script type="text/javascript" src="../js/prettify.js"></script>
<script src="../templates/header.js" type="text/javascript"></script>
<div id="left">
<noscript>Please turn on Javascript to view this menu</noscript>
@@ -62,7 +63,7 @@
javadocs</a> for a complete list of methods.
</p>
-<div class="source"><pre>package org.slf4j;
+<pre class="prettyprint source">package org.slf4j;
public class MDC {
//Put a context value as identified by <em>key</em>
@@ -77,7 +78,7 @@
//Clear all entries in the MDC.
<b>public static void clear();</b>
-}</pre></div>
+}</pre>
<p>The <code>MDC</code> class contains only static methods. It
lets the developer place information in a <em>diagnostic
@@ -100,7 +101,7 @@
</p>
<em>Example 7.1: Basic MDC usage (<a href="../xref/chapter7/SimpleMDC.html">
logback-examples/src/main/java/chapter7/SimpleMDC.java)</a></em>
-<div class="source"><pre>package chapter7;
+<pre class="prettyprint source">package chapter7;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -135,7 +136,7 @@
[ SNIP ]
-}</pre></div>
+}</pre>
<p>The main method starts by associating the value
<em>Dorothy</em> with the key <em>first</em> in the
@@ -150,11 +151,11 @@
relevant section from that file.
</p>
- <p class="source"><appender name="CONSOLE"
- class="ch.qos.logback.core.ConsoleAppender"> <layout
- class="ch.qos.logback.classic.PatternLayout">
+ <pre class="prettyprint source"><appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
+ <layout>
<Pattern><b>%X{first} %X{last}</b> - %m%n</Pattern>
- </layout> </appender></p>
+ </layout>
+</appender></pre>
@@ -215,7 +216,7 @@
<em>Example 7.2: The service interface (<a href="../xref/chapter7/NumberCruncher.html">
logback-examples/src/main/java/chapter7/NumberCruncher.java)</a></em>
-<div class="source"><pre>package chapter7;
+<pre class="prettyprint source">package chapter7;
import java.rmi.Remote;
import java.rmi.RemoteException;
@@ -229,7 +230,7 @@
* <em>distinct</em> factor's as an integer array.
* */
int[] factor(int number) throws RemoteException;
-}</pre></div>
+}</pre>
<p>
The <code>NumberCruncherServer</code> application, listed in Example 7.3 below,
@@ -239,7 +240,7 @@
<em>Example 7.3: The server side (<a href="../xref/chapter7/NumberCruncherServer.html">
logback-examples/src/main/java/chapter7/NumberCruncherServer.java)</a></em>
-<div class="source"><pre>package chapter7;
+<pre class="prettyprint source">package chapter7;
import java.rmi.RemoteException;
import java.rmi.registry.LocateRegistry;
@@ -387,7 +388,7 @@
return;
}
}
-}</pre></div>
+}</pre>
<p>
The implementation of the <code>factor(int number)</code> method is
@@ -416,11 +417,9 @@
The <em>mdc1.xml</em> configuration file is listed below:
</p>
<em>Example 7.4: Configuration file (logback-examples/src/main/java/chapter7/mdc1.xml)</em>
-<div class="source"><pre><configuration>
-
- <appender name="CONSOLE"
- class="ch.qos.logback.core.ConsoleAppender">
- <layout class="ch.qos.logback.classic.PatternLayout">
+<pre class="prettyprint source"><configuration>
+ <appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
+ <layout>
<Pattern>%-4r [%thread] %-5level <b>C:%X{client} N:%X{number}</b> - %msg%n</Pattern>
</layout>
</appender>
@@ -428,7 +427,7 @@
<root level="debug">
<appender-ref ref="CONSOLE"/>
</root>
-</configuration></pre></div>
+</configuration></pre>
<p>
Note the use of the <em>%X</em> conversion specifier within the
@@ -532,7 +531,7 @@
<em>Example 7.5: User servlet filter (<a href="../xref/chapter7/UserServletFilter.html">
logback-examples/src/main/java/chapter7/UserServletFilter.java)</a></em>
-<div class="source"><pre>package chapter7;
+<pre class="prettyprint source">package chapter7;
import java.io.IOException;
import java.security.Principal;
@@ -593,8 +592,7 @@
userRegistered = true;
}
}
-}</pre></div>
-
+}</pre>
<p>
When the filter's <code>doFilter()</code> method is called, is first looks for a
Modified: logback/trunk/logback-site/src/site/pages/manual/migrationFromLog4j.html
==============================================================================
--- logback/trunk/logback-site/src/site/pages/manual/migrationFromLog4j.html (original)
+++ logback/trunk/logback-site/src/site/pages/manual/migrationFromLog4j.html Sat Aug 8 17:28:39 2009
@@ -8,10 +8,11 @@
<link rel="stylesheet" type="text/css" href="../css/common.css" />
<link rel="stylesheet" type="text/css" href="../css/screen.css" media="screen" />
<link rel="stylesheet" type="text/css" href="../css/_print.css" media="print" />
-
+ <link rel="stylesheet" type="text/css" href="../css/prettify.css" media="screen" />
</head>
- <body>
+ <body onload="prettyPrint()">
<script type="text/javascript">prefix='../'</script>
+ <script type="text/javascript" src="../js/prettify.js"></script>
<script src="../templates/header.js" type="text/javascript"></script>
<div id="left">
<noscript>Please turn on Javascript to view this menu</noscript>
@@ -65,7 +66,7 @@
</p>
- <p class="source">package chapter11;
+ <pre class="prettyprint source">package chapter11;
import org.apache.log4j.Layout;
import org.apache.log4j.spi.LoggingEvent;
@@ -83,13 +84,13 @@
public boolean ignoresThrowable() {
return true;
}
-}</p>
+}</pre>
<p>The logback-classic equivalent named <a
href="../xref/chapter11/TrivialLogbackLayout.html">TrivialLogbackLayout</a>
would be </p>
- <p class="source">package chapter11;
+ <pre class="prettyprint source">package chapter11;
import ch.qos.logback.classic.spi.ILoggingEvent;
import ch.qos.logback.core.LayoutBase;
@@ -99,7 +100,7 @@
public String <b>doLayout</b>(ILoggingEvent loggingEvent) {
return loggingEvent.getMessage();
}
-} </p>
+} </pre>
<p>As you can see, in a logback-classic layout, the formatting
method is named <code>doLayout</code> instead of
@@ -133,7 +134,7 @@
href="../xref/chapter11/TrivialLog4jLayout.html">TrivialLog4jLayout</a>
which writes on the console the string returned by its layout.</p>
- <p class="source">package chapter11;
+ <pre class="prettyprint source">package chapter11;
import org.apache.log4j.AppenderSkeleton;
import org.apache.log4j.spi.LoggingEvent;
@@ -153,14 +154,14 @@
public boolean requiresLayout() {
return true;
}
-}</p>
+}</pre>
<p>The logback-classic equivalent named <a
href="../xref/chapter11/TrivialLogbackAppender.html">TrivialLogbackAppender</a>
would be written as</p>
- <p class="source">package chapter11;
+ <pre class="prettyprint source">package chapter11;
import ch.qos.logback.classic.spi.ILoggingEvent;
import ch.qos.logback.core.AppenderBase;
@@ -184,7 +185,7 @@
String s = this.layout.doLayout(loggingevent);
System.out.println(s);
}
-}</p>
+}</pre>
<p>Comparing the two classes, you should notice that the contents
Modified: logback/trunk/logback-site/src/site/pages/manual/onJoran.html
==============================================================================
--- logback/trunk/logback-site/src/site/pages/manual/onJoran.html (original)
+++ logback/trunk/logback-site/src/site/pages/manual/onJoran.html Sat Aug 8 17:28:39 2009
@@ -8,10 +8,11 @@
<link rel="stylesheet" type="text/css" href="../css/common.css" />
<link rel="stylesheet" type="text/css" href="../css/screen.css" media="screen" />
<link rel="stylesheet" type="text/css" href="../css/_print.css" media="print" />
-
+ <link rel="stylesheet" type="text/css" href="../css/prettify.css" media="screen" />
</head>
- <body>
+ <body onload="prettyPrint()">
<script type="text/javascript">prefix='../'</script>
+ <script type="text/javascript" src="../js/prettify.js"></script>
<script src="../templates/header.js" type="text/javascript"></script>
<div id="left">
<noscript>Please turn on Javascript to view this menu</noscript>
@@ -162,7 +163,7 @@
</p>
- <p class="source">package ch.qos.logback.core.joran.action;
+ <pre class="prettyprint source">package ch.qos.logback.core.joran.action;
import org.xml.sax.Attributes;
import ch.qos.logback.core.joran.spi.ExecutionContext;
@@ -183,7 +184,7 @@
*/
public abstract void end(InterpretationContext ec, String name)
throws ActionException;
-}</p>
+}</pre>
<p>Thus, every action must implement the begin and end methods.</p>
@@ -302,9 +303,9 @@
(logback-examples/src/main/java/chapter10/calculator/calculator1.xml)</em>
<em> </em>
- <p class="source"><computation name="total">
+ <pre class="prettyprint source"><computation name="total">
<literal value="3"/>
-</computation></p>
+</computation></pre>
<p>In the <a href="../xref/chapter10/calculator/Calculator1.html">
<code>Calculator1</code></a> application, we declare various
@@ -383,13 +384,13 @@
<em>Example 10.<span class="autoEx"/>: Calculator configuration
file
(logback-examples/src/main/java/chapter10/calculator/calculator2.xml)</em>
- <div class="source"><pre><computation name="toto">
+ <pre class="prettyprint source"><computation name="toto">
<literal value="7"/>
<literal value="3"/>
<add/>
<literal value="3"/>
<multiply/>
-</computation></pre></div>
+</computation></pre>
<p>As in the previous example, in response to the <literal>
@@ -431,7 +432,7 @@
<em>Example 10.<span class="autoEx"/>: Calculator configuration file
(logback-examples/src/main/java/chapter10/calculator/calculator3.xml)</em>
-<div class="source"><pre><computation name="toto">
+<pre class="prettyprint source"><computation name="toto">
<computation>
<literal value="7"/>
<literal value="3"/>
@@ -440,7 +441,7 @@
<literal value="3"/>
<multiply/>
-</computation></pre></div>
+</computation></pre>
<p>Much like the use of parentheses in an algebrical equation, the
presence of a <code>computation</code> element nested in another is
@@ -515,7 +516,7 @@
<em>Example 10.<span class="autoEx"/>: Usage of implicit rules
(logback-examples/src/main/java/chapter10/implicit/implicit1.xml)</em>
- <p class="source"><foo>
+ <pre class="prettyprint source"><foo>
<xyz printme="true">
<abc printme="true"/>
</xyz>
@@ -524,7 +525,7 @@
<foo printme="true"/>
-</foo></p>
+</foo></pre>
<p>Running</p>
@@ -671,8 +672,8 @@
<code>NewRuleCalculator</code>.
</p>
- <p class="source">ruleMap.put(new Pattern("*/computation"), new ComputationAction1());
-<b>ruleStore.addRule(new Pattern("/computation/new-rule"), new NewRuleAction());</b></p>
+ <pre class="prettyprint source">ruleMap.put(new Pattern("*/computation"), new ComputationAction1());
+<b>ruleStore.addRule(new Pattern("/computation/new-rule"), new NewRuleAction());</b></pre>
<p><a
href="../xref/ch/qos/logback/core/joran/action/NewRuleAction.html"><code>NewRuleAction</code></a>,
@@ -687,8 +688,8 @@
<p>Here is how new rules can be declared in an xml file:</p>
- <p class="source"><new-rule pattern="*/computation/literal"
- actionClass="chapter10.calculator.LiteralAction"/></p>
+ <pre class="prettyprint source"><new-rule pattern="*/computation/literal"
+ actionClass="chapter10.calculator.LiteralAction"/></pre>
<p>Using such new-rule declarations, we can transform
<code>NewRuleCalculator</code> to behave like the
@@ -699,7 +700,7 @@
rules on the fly
(logback-examples/src/main/java/chapter10/newrule/new-rule.xml)</em>
- <p class="source"><computation name="toto">
+ <pre class="prettyprint source"><computation name="toto">
<new-rule pattern="*/computation/literal"
actionClass="chapter10.calculator.LiteralAction"/>
<new-rule pattern="*/computation/add"
@@ -715,7 +716,7 @@
<literal value="3"/>
<multiply/>
-</computation></p>
+</computation></pre>
<p class="command">java java chapter10.newRule.NewRuleCalculator src/main/java/chapter10/newRule/new-rule.xml</p>
1
0

07 Aug '09
Author: ceki
Date: Fri Aug 7 23:33:38 2009
New Revision: 2422
Modified:
logback/trunk/logback-site/src/site/pages/news.html
Log:
- blurb about LBCORE-61 (incomplete)
Modified: logback/trunk/logback-site/src/site/pages/news.html
==============================================================================
--- logback/trunk/logback-site/src/site/pages/news.html (original)
+++ logback/trunk/logback-site/src/site/pages/news.html Fri Aug 7 23:33:38 2009
@@ -49,6 +49,14 @@
<a href="http://jira.qos.ch/browse/LBCORE-90">LBCORE-90</a> as
reported by Valery Shorin.</p>
+
+ <p>The TimeBasedTriggeringPolicy has been heavily refactored. It
+ is now possible to trigger rolling by <a
+ href="">XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXtime as well as by
+ size</a>, fixing <a
+ href="http://jira.qos.ch/browse/LBCORE-61">LBCORE-61</a>.
+ </p>
+
<hr width="80%" align="center" />
<h3>15th of July 2009 - Release of version 0.9.16</h3>
1
0

[JIRA] Created: (LBCORE-61) TimeBasedRollingPolicy can not be used with any other triggering policies
by Szel Zoltan (JIRA) 07 Aug '09
by Szel Zoltan (JIRA) 07 Aug '09
07 Aug '09
TimeBasedRollingPolicy can not be used with any other triggering policies
-------------------------------------------------------------------------
Key: LBCORE-61
URL: http://jira.qos.ch/browse/LBCORE-61
Project: logback-core
Issue Type: Bug
Reporter: Szel Zoltan
Assignee: Logback dev list
Priority: Critical
If someone would like to have a time based rolling policy with a size based triggering policy, than the user will get a NullPointerException,:
at ch.qos.logback.core.rolling.helper.Compress.GZCompress(Compress.java:130)
at ch.qos.logback.core.rolling.TimeBasedRollingPolicy.rollover(TimeBasedRollingPolicy.java:142)
at ch.qos.logback.core.rolling.RollingFileAppender.rollover(RollingFileAppender.java:91)
at ch.qos.logback.core.rolling.RollingFileAppender.subAppend(RollingFileAppender.java:116)
at ch.qos.logback.core.WriterAppender.append(WriterAppender.java:124)
at ch.qos.logback.core.AppenderBase.doAppend(AppenderBase.java:81)
at ch.qos.logback.core.spi.AppenderAttachableImpl.appendLoopOnAppenders(AppenderAttachableImpl.java:51)
at ch.qos.logback.classic.Logger.appendLoopOnAppenders(Logger.java:282)
at ch.qos.logback.classic.Logger.callAppenders(Logger.java:266)
at ch.qos.logback.classic.Logger.buildLoggingEventAndAppend(Logger.java:487)
at ch.qos.logback.classic.Logger.filterAndLog(Logger.java:479)
The cause of this issue is the isTriggeringEvent method in the TimeBasedRollingPolicy which has a side effect, namely it prepares the file name of the file which is about to rotate. If someone uses a triggering policy other than the same TimeBasedRollingPolicy, than the isTriggeringEvent method will not be called, hence the elapsedPeriodFileName will be null, hence a null pointer exception will be thrown in the start of the compression or while renaming.
Please modify the isTriggeringEvent to not have this side effect + the rollover logic to capture the time information from the current event.
Thanks,
Zoltan
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://jira.qos.ch/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira
2
5

svn commit: r2421 - in logback/trunk: logback-core/src/main/java/ch/qos/logback/core/rolling logback-core/src/test/java/ch/qos/logback/core/rolling logback-site/src/site/pages
by noreply.ceki@qos.ch 07 Aug '09
by noreply.ceki@qos.ch 07 Aug '09
07 Aug '09
Author: ceki
Date: Fri Aug 7 23:02:57 2009
New Revision: 2421
Modified:
logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/RollingPolicyBase.java
logback/trunk/logback-core/src/test/java/ch/qos/logback/core/rolling/TimeBasedRollingWithArchiveRemovalTest.java
logback/trunk/logback-site/src/site/pages/news.html
Log:
- minor changes
- added blurb about LBCORE-90 being fixed
Modified: logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/RollingPolicyBase.java
==============================================================================
--- logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/RollingPolicyBase.java (original)
+++ logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/RollingPolicyBase.java Fri Aug 7 23:02:57 2009
@@ -11,7 +11,6 @@
import ch.qos.logback.core.FileAppender;
import ch.qos.logback.core.rolling.helper.CompressionMode;
-import ch.qos.logback.core.rolling.helper.FileFilterUtil;
import ch.qos.logback.core.rolling.helper.FileNamePattern;
import ch.qos.logback.core.spi.ContextAwareBase;
Modified: logback/trunk/logback-core/src/test/java/ch/qos/logback/core/rolling/TimeBasedRollingWithArchiveRemovalTest.java
==============================================================================
--- logback/trunk/logback-core/src/test/java/ch/qos/logback/core/rolling/TimeBasedRollingWithArchiveRemovalTest.java (original)
+++ logback/trunk/logback-core/src/test/java/ch/qos/logback/core/rolling/TimeBasedRollingWithArchiveRemovalTest.java Fri Aug 7 23:02:57 2009
@@ -174,7 +174,7 @@
rfa.stop();
}
- void findAllInFolderRecursively(File dir, List<File> fileList,
+ void findAllInFolderRecursivelyByStringContains(File dir, List<File> fileList,
final String pattern) {
if (dir.isDirectory()) {
File[] match = dir.listFiles(new FileFilter() {
@@ -185,13 +185,13 @@
for (File f : match) {
fileList.add(f);
if (f.isDirectory()) {
- findAllInFolderRecursively(f, fileList, pattern);
+ findAllInFolderRecursivelyByStringContains(f, fileList, pattern);
}
}
}
}
- void findFilesInFolderRecursively(File dir, List<File> fileList,
+ void findFilesInFolderRecursivelyByPatterMatch(File dir, List<File> fileList,
final String pattern) {
if (dir.isDirectory()) {
File[] match = dir.listFiles(new FileFilter() {
@@ -201,7 +201,7 @@
});
for (File f : match) {
if (f.isDirectory()) {
- findFilesInFolderRecursively(f, fileList, pattern);
+ findFilesInFolderRecursivelyByPatterMatch(f, fileList, pattern);
} else {
fileList.add(f);
}
@@ -234,22 +234,17 @@
return (maxHistory + 1) * 2 + slashCount;
}
- int expectedCountWithDirs_NoSlash(int maxHistory) {
- // one file and one directory per archived log file
- return (maxHistory + 1) * 2;
- }
-
void check(int expectedCount) {
File dir = new File(randomOutputDir);
List<File> fileList = new ArrayList<File>();
- findAllInFolderRecursively(dir, fileList, "clean");
+ findAllInFolderRecursivelyByStringContains(dir, fileList, "clean");
assertEquals(expectedCount, fileList.size());
}
void checkPatternCompliance(int expectedClassCount, String regex) {
File dir = new File(randomOutputDir);
List<File> fileList = new ArrayList<File>();
- findFilesInFolderRecursively(dir, fileList, regex);
+ findFilesInFolderRecursivelyByPatterMatch(dir, fileList, regex);
System.out.println("regex="+regex);
System.out.println("fileList="+fileList);
Set<String> set = groupByClass(fileList, regex);
Modified: logback/trunk/logback-site/src/site/pages/news.html
==============================================================================
--- logback/trunk/logback-site/src/site/pages/news.html (original)
+++ logback/trunk/logback-site/src/site/pages/news.html Fri Aug 7 23:02:57 2009
@@ -44,6 +44,11 @@
truncate mode when an application stops and is quickly re-started,
any pre-existing log file for the current period will be lost.</p>
+ <p>The <code>activeFile</code> field in
+ <code>RollingFileAppender</code> is now properly updated, fixing
+ <a href="http://jira.qos.ch/browse/LBCORE-90">LBCORE-90</a> as
+ reported by Valery Shorin.</p>
+
<hr width="80%" align="center" />
<h3>15th of July 2009 - Release of version 0.9.16</h3>
1
0

[JIRA] Created: (LBCORE-90) RollingFileAppender calls triggeringPolicy.isTriggeringEvent(activeFile, event) with the same activeFile
by Valery Shorin (JIRA) 07 Aug '09
by Valery Shorin (JIRA) 07 Aug '09
07 Aug '09
RollingFileAppender calls triggeringPolicy.isTriggeringEvent(activeFile, event) with the same activeFile
--------------------------------------------------------------------------------------------------------
Key: LBCORE-90
URL: http://jira.qos.ch/browse/LBCORE-90
Project: logback-core
Issue Type: Bug
Components: Appender
Affects Versions: 0.9.14
Reporter: Valery Shorin
Assignee: Logback dev list
In subAppend(...) method RollingFileAppender calls triggeringPolicy.isTriggeringEvent(activeFile, event) method with activeFileCache variable as first parameter, but activeFileCache variable initialized in start() method of RollingFileAppender and not changed anymore.
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://jira.qos.ch/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira
2
6

svn commit: r2420 - in logback/trunk/logback-core/src: main/java/ch/qos/logback/core/rolling main/java/ch/qos/logback/core/rolling/helper test/java/ch/qos/logback/core/rolling
by noreply.ceki@qos.ch 07 Aug '09
by noreply.ceki@qos.ch 07 Aug '09
07 Aug '09
Author: ceki
Date: Fri Aug 7 22:32:53 2009
New Revision: 2420
Modified:
logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/RollingFileAppender.java
logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/SizeAndTimeBasedFNATP.java
logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/helper/DefaultArchiveRemover.java
logback/trunk/logback-core/src/test/java/ch/qos/logback/core/rolling/TimeBasedRollingWithArchiveRemovalTest.java
Log:
- fixed LBCORE-90
Modified: logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/RollingFileAppender.java
==============================================================================
--- logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/RollingFileAppender.java (original)
+++ logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/RollingFileAppender.java Fri Aug 7 22:32:53 2009
@@ -27,7 +27,7 @@
* @author Ceki Gülcü
*/
public class RollingFileAppender<E> extends FileAppender<E> {
- File activeFile;
+ File currentlyActiveFile;
TriggeringPolicy<E> triggeringPolicy;
RollingPolicy rollingPolicy;
@@ -70,7 +70,7 @@
}
}
- activeFile = new File(getFile());
+ currentlyActiveFile = new File(getFile());
addInfo("Active log file name: " + getFile());
super.start();
}
@@ -123,6 +123,10 @@
}
try {
+ // update the currentlyActiveFile
+ // http://jira.qos.ch/browse/LBCORE-90
+ currentlyActiveFile = new File(rollingPolicy.getActiveFileName());
+
// This will also close the file. This is OK since multiple
// close operations are safe.
this.openFile(rollingPolicy.getActiveFileName());
@@ -141,7 +145,7 @@
// We need to synchronize on triggeringPolicy so that only one rollover
// occurs at a time
synchronized (triggeringPolicy) {
- if (triggeringPolicy.isTriggeringEvent(activeFile, event)) {
+ if (triggeringPolicy.isTriggeringEvent(currentlyActiveFile, event)) {
rollover();
}
}
Modified: logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/SizeAndTimeBasedFNATP.java
==============================================================================
--- logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/SizeAndTimeBasedFNATP.java (original)
+++ logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/SizeAndTimeBasedFNATP.java Fri Aug 7 22:32:53 2009
@@ -65,6 +65,7 @@
private int invocationCounter;
public boolean isTriggeringEvent(File activeFile, final E event) {
+
long time = getCurrentTime();
if (time >= nextCheck) {
Date dateInElapsedPeriod = dateInCurrentPeriod;
Modified: logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/helper/DefaultArchiveRemover.java
==============================================================================
--- logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/helper/DefaultArchiveRemover.java (original)
+++ logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/helper/DefaultArchiveRemover.java Fri Aug 7 22:32:53 2009
@@ -66,11 +66,8 @@
public void clean(Date now) {
Date date2delete = rc.getRelativeDate(now, periodOffset);
-
String filename = fileNamePattern.convert(date2delete);
-
File file2Delete = new File(filename);
-
if (file2Delete.exists() && file2Delete.isFile()) {
file2Delete.delete();
if (parentClean) {
Modified: logback/trunk/logback-core/src/test/java/ch/qos/logback/core/rolling/TimeBasedRollingWithArchiveRemovalTest.java
==============================================================================
--- logback/trunk/logback-core/src/test/java/ch/qos/logback/core/rolling/TimeBasedRollingWithArchiveRemovalTest.java (original)
+++ logback/trunk/logback-core/src/test/java/ch/qos/logback/core/rolling/TimeBasedRollingWithArchiveRemovalTest.java Fri Aug 7 22:32:53 2009
@@ -1,12 +1,16 @@
package ch.qos.logback.core.rolling;
import static org.junit.Assert.assertEquals;
-
+import static org.junit.Assert.assertTrue;
import java.io.File;
import java.io.FileFilter;
import java.util.ArrayList;
+import java.util.HashSet;
import java.util.List;
+import java.util.Set;
import java.util.concurrent.TimeUnit;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
import org.junit.After;
import org.junit.Before;
@@ -75,15 +79,18 @@
slashCount = computeSlashCount(MONTHLY_DATE_PATTERN);
// large maxPeriod, a 3 times as many number of periods to simulate
doRollover(randomOutputDir + "clean-%d{" + MONTHLY_DATE_PATTERN + "}.txt",
- MILLIS_IN_MONTH, 20, 20 * 3, expectedCountWithoutDirs(20));
+ MILLIS_IN_MONTH, 20, 20 * 3);
+ check(expectedCountWithoutDirs(20));
}
@Test
public void montlyRolloverOverManyPeriods() throws Exception {
+ System.out.println(randomOutputDir);
// small maxHistory, many periods
slashCount = computeSlashCount(MONTHLY_CROLOLOG_DATE_PATTERN);
doRollover(randomOutputDir + "/%d{" + MONTHLY_CROLOLOG_DATE_PATTERN
- + "}/clean.txt.zip", MILLIS_IN_MONTH, 5, 40, expectedCountWithDirs(5));
+ + "}/clean.txt.zip", MILLIS_IN_MONTH, 2, 40);
+ check(expectedCountWithDirs(2));
}
@Test
@@ -91,41 +98,47 @@
slashCount = computeSlashCount(DAILY_DATE_PATTERN);
doRollover(
randomOutputDir + "clean-%d{" + DAILY_DATE_PATTERN + "}.txt.zip",
- MILLIS_IN_DAY, 5, 5 * 3, expectedCountWithoutDirs(5));
+ MILLIS_IN_DAY, 5, 5 * 3);
+ check(expectedCountWithoutDirs(5));
}
@Test
public void dailyCronologRollover() throws Exception {
slashCount = computeSlashCount(DAILY_CROLOLOG_DATE_PATTERN);
doRollover(randomOutputDir + "/%d{" + DAILY_CROLOLOG_DATE_PATTERN
- + "}/clean.txt.zip", MILLIS_IN_DAY, 8, 8 * 3, expectedCountWithDirs(8));
+ + "}/clean.txt.zip", MILLIS_IN_DAY, 8, 8 * 3);
+ check(expectedCountWithDirs(8));
}
@Test
public void dailySizeBasedRollover() throws Exception {
SizeAndTimeBasedFNATP<Object> sizeAndTimeBasedFNATP = new SizeAndTimeBasedFNATP<Object>();
- sizeAndTimeBasedFNATP.setMaxFileSize("1");
+ sizeAndTimeBasedFNATP.setMaxFileSize("10");
tbfnatp = sizeAndTimeBasedFNATP;
slashCount = computeSlashCount(DAILY_DATE_PATTERN);
- doRollover(randomOutputDir + "/%d{" + DAILY_DATE_PATTERN
- + "}-clean.%i.zip", MILLIS_IN_DAY, 5, 5 * 4, expectedCountWithoutDirs(5));
+ doRollover(
+ randomOutputDir + "/%d{" + DAILY_DATE_PATTERN + "}-clean.%i.zip",
+ MILLIS_IN_DAY, 5, 5 * 4);
+ checkPatternCompliance(5 + 1 + slashCount,
+ "\\d{4}-\\d{2}-\\d{2}-clean.(\\d).zip");
}
-
@Test
public void dailyChronologSizeBasedRollover() throws Exception {
SizeAndTimeBasedFNATP<Object> sizeAndTimeBasedFNATP = new SizeAndTimeBasedFNATP<Object>();
- sizeAndTimeBasedFNATP.setMaxFileSize("1");
+ sizeAndTimeBasedFNATP.setMaxFileSize("10");
tbfnatp = sizeAndTimeBasedFNATP;
- slashCount = computeSlashCount(DAILY_CROLOLOG_DATE_PATTERN);
- doRollover(randomOutputDir + "/%d{" + DAILY_DATE_PATTERN
- + "}/clean.%i.zip", MILLIS_IN_DAY, 5, 5 * 4, xexpectedCountWithDirs_NoSlash(5));
+ slashCount = 1;
+ doRollover(
+ randomOutputDir + "/%d{" + DAILY_DATE_PATTERN + "}/clean.%i.zip",
+ MILLIS_IN_DAY, 5, 5 * 4);
+ checkDirPatternCompliance(6);
}
void doRollover(String fileNamePattern, long periodDurationInMillis,
- int maxHistory, int simulatedNumberOfPeriods, int expectedCount) throws Exception {
+ int maxHistory, int simulatedNumberOfPeriods) throws Exception {
long currentTime = System.currentTimeMillis();
RollingFileAppender<Object> rfa = new RollingFileAppender<Object>();
@@ -148,7 +161,9 @@
long runLength = simulatedNumberOfPeriods * ticksPerPeriod;
for (long i = 0; i < runLength; i++) {
- rfa.doAppend("Hello---" + i);
+ rfa
+ .doAppend("Hello ----------------------------------------------------------"
+ + i);
tbrp.timeBasedTriggering.setCurrentTime(addTime(tbrp.timeBasedTriggering
.getCurrentTime(), periodDurationInMillis / ticksPerPeriod));
@@ -157,54 +172,115 @@
}
}
rfa.stop();
- check(expectedCount);
}
- void recursiveDirectoryDescent(File dir, List<File> fileList,
+ void findAllInFolderRecursively(File dir, List<File> fileList,
final String pattern) {
if (dir.isDirectory()) {
File[] match = dir.listFiles(new FileFilter() {
public boolean accept(File f) {
- if (f.isDirectory()) {
- return true;
- } else {
- return f.getName().contains(pattern);
- }
+ return (f.isDirectory() || f.getName().contains(pattern));
}
});
for (File f : match) {
fileList.add(f);
if (f.isDirectory()) {
- recursiveDirectoryDescent(f, fileList, pattern);
+ findAllInFolderRecursively(f, fileList, pattern);
+ }
+ }
+ }
+ }
+
+ void findFilesInFolderRecursively(File dir, List<File> fileList,
+ final String pattern) {
+ if (dir.isDirectory()) {
+ File[] match = dir.listFiles(new FileFilter() {
+ public boolean accept(File f) {
+ return (f.isDirectory() || f.getName().matches(pattern));
+ }
+ });
+ for (File f : match) {
+ if (f.isDirectory()) {
+ findFilesInFolderRecursively(f, fileList, pattern);
+ } else {
+ fileList.add(f);
+ }
+ }
+ }
+ }
+
+ void findFoldersInFolderRecursively(File dir, List<File> fileList) {
+ if (dir.isDirectory()) {
+ File[] match = dir.listFiles(new FileFilter() {
+ public boolean accept(File f) {
+ return f.isDirectory();
}
+ });
+ for (File f : match) {
+ fileList.add(f);
+ findFoldersInFolderRecursively(f, fileList);
}
}
}
int expectedCountWithoutDirs(int maxHistory) {
// maxHistory plus the currently active file
- return maxHistory+1;
+ return maxHistory + 1;
}
-
+
int expectedCountWithDirs(int maxHistory) {
// each slash adds a new directory
// + one file and one directory per archived log file
return (maxHistory + 1) * 2 + slashCount;
}
- int xexpectedCountWithDirs_NoSlash(int maxHistory) {
- // each slash adds a new directory
- // + one file and one directory per archived log file
+ int expectedCountWithDirs_NoSlash(int maxHistory) {
+ // one file and one directory per archived log file
return (maxHistory + 1) * 2;
}
-
+
void check(int expectedCount) {
File dir = new File(randomOutputDir);
List<File> fileList = new ArrayList<File>();
- recursiveDirectoryDescent(dir, fileList, "clean");
+ findAllInFolderRecursively(dir, fileList, "clean");
assertEquals(expectedCount, fileList.size());
}
+ void checkPatternCompliance(int expectedClassCount, String regex) {
+ File dir = new File(randomOutputDir);
+ List<File> fileList = new ArrayList<File>();
+ findFilesInFolderRecursively(dir, fileList, regex);
+ System.out.println("regex="+regex);
+ System.out.println("fileList="+fileList);
+ Set<String> set = groupByClass(fileList, regex);
+ assertEquals(expectedClassCount, set.size());
+ }
+
+ void checkDirPatternCompliance(int expectedClassCount) {
+ File dir = new File(randomOutputDir);
+ List<File> fileList = new ArrayList<File>();
+ findFoldersInFolderRecursively(dir, fileList);
+ for(File f: fileList) {
+ assertTrue(f.list().length >= 1);
+ }
+ assertEquals(expectedClassCount, fileList.size());
+ }
+
+
+ Set<String> groupByClass(List<File> fileList, String regex) {
+ Pattern p = Pattern.compile(regex);
+ Set<String> set = new HashSet<String>();
+ for (File f : fileList) {
+ String n = f.getName();
+ Matcher m = p.matcher(n);
+ m.matches();
+ int begin = m.start(1);
+ int end = m.end(1);
+ set.add(n.substring(0, begin) + n.substring(end));
+ }
+ return set;
+ }
+
static long addTime(long currentTime, long timeToWait) {
return currentTime + timeToWait;
}
1
0

svn commit: r2419 - in logback/trunk/logback-core/src: main/java/ch/qos/logback/core/rolling main/java/ch/qos/logback/core/rolling/helper test/java/ch/qos/logback/core/rolling test/java/ch/qos/logback/core/rolling/helper
by noreply.ceki@qos.ch 07 Aug '09
by noreply.ceki@qos.ch 07 Aug '09
07 Aug '09
Author: ceki
Date: Fri Aug 7 18:30:50 2009
New Revision: 2419
Added:
logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/helper/DatePatternToRegexUtil.java
- copied, changed from r2417, /logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/helper/DatePatternToSRegexUtil.java
logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/helper/SizeAndTimeBasedArchiveRemover.java
logback/trunk/logback-core/src/test/java/ch/qos/logback/core/rolling/TimeBasedRollingWithArchiveRemovalTest.java
- copied, changed from r2418, /logback/trunk/logback-core/src/test/java/ch/qos/logback/core/rolling/TimeBasedRollingWithHistoryCleanTest.java
Removed:
logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/helper/DatePatternToSRegexUtil.java
logback/trunk/logback-core/src/test/java/ch/qos/logback/core/rolling/TimeBasedRollingWithHistoryCleanTest.java
Modified:
logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/RollingPolicyBase.java
logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/SizeAndTimeBasedFNATP.java
logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/helper/DateTokenConverter.java
logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/helper/DefaultArchiveRemover.java
logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/helper/FileFilterUtil.java
logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/helper/FileNamePattern.java
logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/helper/SequenceToRegex4SDF.java
logback/trunk/logback-core/src/test/java/ch/qos/logback/core/rolling/PackageTest.java
logback/trunk/logback-core/src/test/java/ch/qos/logback/core/rolling/helper/DatePatternToRegexTest.java
logback/trunk/logback-core/src/test/java/ch/qos/logback/core/rolling/helper/FileNamePatternTest.java
Log:
- FileNamePattern now slashifies its pattern argument at construction time
This eliminates the need to slashify regular expression at a later time
(since the original pattern is already slashified)
- While cleaning archived log files, empty fodlers are taken into account, especially if
they are in cronolog-style "/var/tmp/2009/08/04/foo.log".
- old archives are cleaned for time-based triggering as well as size-and-time-based triggering
- relevant test cases
Modified: logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/RollingPolicyBase.java
==============================================================================
--- logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/RollingPolicyBase.java (original)
+++ logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/RollingPolicyBase.java Fri Aug 7 18:30:50 2009
@@ -11,6 +11,7 @@
import ch.qos.logback.core.FileAppender;
import ch.qos.logback.core.rolling.helper.CompressionMode;
+import ch.qos.logback.core.rolling.helper.FileFilterUtil;
import ch.qos.logback.core.rolling.helper.FileNamePattern;
import ch.qos.logback.core.spi.ContextAwareBase;
@@ -24,6 +25,7 @@
RollingPolicy {
protected CompressionMode compressionMode = CompressionMode.NONE;
protected FileNamePattern fileNamePattern;
+ // fileNamePatternStr is always slashified, see setter
protected String fileNamePatternStr;
private FileAppender parent;
@@ -76,7 +78,6 @@
}
public void setParent(FileAppender appender) {
- addInfo("Adding parent to RollingPolicy: " + appender.getName());
this.parent = appender;
}
Modified: logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/SizeAndTimeBasedFNATP.java
==============================================================================
--- logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/SizeAndTimeBasedFNATP.java (original)
+++ logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/SizeAndTimeBasedFNATP.java Fri Aug 7 18:30:50 2009
@@ -14,6 +14,7 @@
import ch.qos.logback.core.joran.spi.NoAutoStart;
import ch.qos.logback.core.rolling.helper.FileFilterUtil;
+import ch.qos.logback.core.rolling.helper.SizeAndTimeBasedArchiveRemover;
import ch.qos.logback.core.util.FileSize;
@NoAutoStart
@@ -30,12 +31,14 @@
// in super.start()
super.start();
+ archiveRemover = new SizeAndTimeBasedArchiveRemover(tbrp.fileNamePattern, rc);
+
// we need to get the correct value of currentPeriodsCounter.
// usually the value is 0, unless the appender or the application
// is stopped and restarted within the same period
if (tbrp.getParentsRawFileProperty() == null) {
- String slashifiedRegex = tbrp.fileNamePattern.toSRegex(dateInCurrentPeriod);
- String stemRegex = FileFilterUtil.afterLastSlash(slashifiedRegex);
+ String regex = tbrp.fileNamePattern.toRegex(dateInCurrentPeriod);
+ String stemRegex = FileFilterUtil.afterLastSlash(regex);
computeCurrentPeriodsHighestCounterValue(stemRegex);
}
started = true;
@@ -79,9 +82,11 @@
}
if (activeFile.length() >= maxFileSize.getSize()) {
+ System.out.println("Size based trigger, currentPeriodsCounter="+currentPeriodsCounter);
elapsedPeriodsFileName = tbrp.fileNamePatternWCS
.convertMultipleArguments(dateInCurrentPeriod, currentPeriodsCounter);
currentPeriodsCounter++;
+ System.out.println("Size based trigger, currentPeriodsCounter="+currentPeriodsCounter);
return true;
}
Copied: logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/helper/DatePatternToRegexUtil.java (from r2417, /logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/helper/DatePatternToSRegexUtil.java)
==============================================================================
--- /logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/helper/DatePatternToSRegexUtil.java (original)
+++ logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/helper/DatePatternToRegexUtil.java Fri Aug 7 18:30:50 2009
@@ -21,21 +21,21 @@
* @author Ceki Gülcü
*
*/
-public class DatePatternToSRegexUtil {
+public class DatePatternToRegexUtil {
final String datePattern;
final int length;
- DatePatternToSRegexUtil(String datePattern) {
+ DatePatternToRegexUtil(String datePattern) {
this.datePattern = datePattern;
length = datePattern.length();
}
- String toSRegex() {
+ String toRegex() {
List<SequenceToRegex4SDF> sequenceList = tokenize();
StringBuilder sb = new StringBuilder();
for (SequenceToRegex4SDF seq : sequenceList) {
- sb.append(seq.toSRegex());
+ sb.append(seq.toRegex());
}
return sb.toString();
}
Modified: logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/helper/DateTokenConverter.java
==============================================================================
--- logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/helper/DateTokenConverter.java (original)
+++ logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/helper/DateTokenConverter.java Fri Aug 7 18:30:50 2009
@@ -67,8 +67,8 @@
return (o instanceof Date);
}
- public String toSRegex() {
- DatePatternToSRegexUtil toRegex = new DatePatternToSRegexUtil(datePattern);
- return toRegex.toSRegex();
+ public String toRegex() {
+ DatePatternToRegexUtil toRegex = new DatePatternToRegexUtil(datePattern);
+ return toRegex.toRegex();
}
}
Modified: logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/helper/DefaultArchiveRemover.java
==============================================================================
--- logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/helper/DefaultArchiveRemover.java (original)
+++ logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/helper/DefaultArchiveRemover.java Fri Aug 7 18:30:50 2009
@@ -13,16 +13,55 @@
import java.io.File;
import java.util.Date;
+import ch.qos.logback.core.pattern.Converter;
+import ch.qos.logback.core.pattern.LiteralConverter;
+
public class DefaultArchiveRemover implements ArchiveRemover {
- FileNamePattern fileNamePattern;
- RollingCalendar rc;
+ final FileNamePattern fileNamePattern;
+ final RollingCalendar rc;
int maxHistory;
int periodOffset;
-
- public DefaultArchiveRemover(FileNamePattern fileNamePattern, RollingCalendar rc) {
+ final boolean parentClean;
+
+ public DefaultArchiveRemover(FileNamePattern fileNamePattern,
+ RollingCalendar rc) {
this.fileNamePattern = fileNamePattern;
this.rc = rc;
+ this.parentClean = computeParentCleaningFlag(fileNamePattern);
+ }
+
+ boolean computeParentCleaningFlag(FileNamePattern fileNamePattern) {
+ DateTokenConverter dtc = fileNamePattern.getDateTokenConverter();
+ // if the date pattern has a /, then we need parent cleaning
+ if(dtc.getDatePattern().indexOf('/') != -1) {
+ return true;
+ }
+ // if the literal string subsequent to the dtc contains a /, we also need
+ // parent cleaning
+
+ Converter<Object> p = fileNamePattern.headTokenConverter;
+
+ // find the date converter
+ while(p != null) {
+ if(p instanceof DateTokenConverter) {
+ break;
+ }
+ p = p.getNext();
+ }
+
+ while(p != null) {
+ if(p instanceof LiteralConverter) {
+ String s = p.convert(null);
+ if(s.indexOf('/') != -1) {
+ return true;
+ }
+ }
+ p = p.getNext();
+ }
+
+ // no /, so we don't need parent cleaning
+ return false;
}
public void clean(Date now) {
@@ -34,12 +73,34 @@
if (file2Delete.exists() && file2Delete.isFile()) {
file2Delete.delete();
+ if (parentClean) {
+ removeFolderIfEmpty(file2Delete.getParentFile(), 0);
+ }
+ }
+ }
+
+ /**
+ * Will remove the directory passed as parameter if empty. After that, if the
+ * parent is also becomes empty, remove the parent dir as well but at most 3
+ * times.
+ *
+ * @param dir
+ * @param recursivityCount
+ */
+ void removeFolderIfEmpty(File dir, int recursivityCount) {
+ // we should never go more than 3 levels higher
+ if (recursivityCount >= 3) {
+ return;
+ }
+ if (dir.isDirectory() && FileFilterUtil.isEmptyDirectory(dir)) {
+ dir.delete();
+ removeFolderIfEmpty(dir.getParentFile(), recursivityCount + 1);
}
}
public void setMaxHistory(int maxHistory) {
this.maxHistory = maxHistory;
- this.periodOffset = -maxHistory -1;
+ this.periodOffset = -maxHistory - 1;
}
}
Modified: logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/helper/FileFilterUtil.java
==============================================================================
--- logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/helper/FileFilterUtil.java (original)
+++ logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/helper/FileFilterUtil.java Fri Aug 7 18:30:50 2009
@@ -48,6 +48,18 @@
}
}
+ static public boolean isEmptyDirectory(File dir) {
+ if (!dir.isDirectory()) {
+ throw new IllegalArgumentException("[" + dir + "] must be a directory");
+ }
+ String[] filesInDir = dir.list();
+ if (filesInDir == null || filesInDir.length == 0) {
+ return true;
+ } else {
+ return false;
+ }
+ }
+
/**
* Return the set of files matching the stemRegex as found in 'directory'. A
* stemRegex does not contain any slash characters or any folder seperators.
@@ -87,7 +99,20 @@
return counter;
}
- static String slashify(String in) {
+ public static String slashify(String in) {
return in.replace('\\', '/');
}
+
+ public static void removeEmptyParentDirectories(File file,
+ int recursivityCount) {
+ // we should never go more than 3 levels higher
+ if (recursivityCount >= 3) {
+ return;
+ }
+ File parent = file.getParentFile();
+ if (parent.isDirectory() && FileFilterUtil.isEmptyDirectory(parent)) {
+ parent.delete();
+ removeEmptyParentDirectories(parent, recursivityCount + 1);
+ }
+ }
}
Modified: logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/helper/FileNamePattern.java
==============================================================================
--- logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/helper/FileNamePattern.java (original)
+++ logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/helper/FileNamePattern.java Fri Aug 7 18:30:50 2009
@@ -46,7 +46,8 @@
Converter<Object> headTokenConverter;
public FileNamePattern(String patternArg, Context contextArg) {
- setPattern(patternArg);
+ // the pattern is slashified
+ setPattern(FileFilterUtil.slashify(patternArg));
setContext(contextArg);
parse();
ConverterUtil.startConverters(this.headTokenConverter);
@@ -141,20 +142,20 @@
}
/**
- * Given date, convert this instance to a slashified regular expression. A
+ * Given date, convert this instance to a regular expression. A
* slashified regex, is a regex with naturally occurring forward slash
* characters replaced by back slashes.
*/
- public String toSRegex(Date date) {
+ public String toRegex(Date date) {
StringBuilder buf = new StringBuilder();
Converter<Object> p = headTokenConverter;
while (p != null) {
if (p instanceof LiteralConverter) {
- buf.append(FileFilterUtil.slashify(p.convert(null)));
+ buf.append(p.convert(null));
} else if (p instanceof IntegerTokenConverter) {
buf.append("(\\d{1,2})");
} else if (p instanceof DateTokenConverter) {
- buf.append(FileFilterUtil.slashify(p.convert(date)));
+ buf.append(p.convert(date));
}
p = p.getNext();
}
@@ -162,19 +163,19 @@
}
/**
- * Given date, convert this instance to a slashified regular expression
+ * Given date, convert this instance to a regular expression
*/
- public String toSRegex() {
+ public String toRegex() {
StringBuilder buf = new StringBuilder();
Converter<Object> p = headTokenConverter;
while (p != null) {
if (p instanceof LiteralConverter) {
- buf.append(FileFilterUtil.slashify(p.convert(null)));
+ buf.append(p.convert(null));
} else if (p instanceof IntegerTokenConverter) {
buf.append("\\d{1,2}");
} else if (p instanceof DateTokenConverter) {
DateTokenConverter<Object> dtc = (DateTokenConverter<Object>) p;
- buf.append(dtc.toSRegex());
+ buf.append(dtc.toRegex());
}
p = p.getNext();
}
Modified: logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/helper/SequenceToRegex4SDF.java
==============================================================================
--- logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/helper/SequenceToRegex4SDF.java (original)
+++ logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/helper/SequenceToRegex4SDF.java Fri Aug 7 18:30:50 2009
@@ -29,8 +29,7 @@
occurrences++;
}
- // slashified regex
- String toSRegex() {
+ String toRegex() {
switch (c) {
case 'G':
return ".*";
@@ -64,12 +63,8 @@
return "(\\+|-)\\d{4}";
case '.':
return "\\.";
- case '\\': // slashify
- String s = "";
- for(int i = 0; i < occurrences;i++) {
- s += "/";
- }
- return s;
+ case '\\':
+ throw new IllegalStateException("Forward slashes are not allowed");
default:
if (occurrences == 1) {
return "" + c;
Added: logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/helper/SizeAndTimeBasedArchiveRemover.java
==============================================================================
--- (empty file)
+++ logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/helper/SizeAndTimeBasedArchiveRemover.java Fri Aug 7 18:30:50 2009
@@ -0,0 +1,45 @@
+/**
+ * Logback: the generic, reliable, fast and flexible logging framework.
+ *
+ * Copyright (C) 2000-2009, QOS.ch
+ *
+ * This library is free software, you can redistribute it and/or modify it under
+ * the terms of the GNU Lesser General Public License as published by the Free
+ * Software Foundation.
+ */
+
+package ch.qos.logback.core.rolling.helper;
+
+import java.io.File;
+import java.util.Date;
+
+public class SizeAndTimeBasedArchiveRemover extends DefaultArchiveRemover {
+
+ public SizeAndTimeBasedArchiveRemover(FileNamePattern fileNamePattern,
+ RollingCalendar rc) {
+ super(fileNamePattern, rc);
+ }
+
+ @Override
+ public void clean(Date now) {
+ Date dateOfPeriodToClean = rc.getRelativeDate(now, periodOffset);
+
+ String regex = fileNamePattern.toRegex(dateOfPeriodToClean);
+ String stemRegex = FileFilterUtil.afterLastSlash(regex);
+ File archive0 = new File(fileNamePattern.convertMultipleArguments(
+ dateOfPeriodToClean, 0));
+
+ File parentDir = archive0.getParentFile();
+ File[] matchingFileArray = FileFilterUtil.filesInFolderMatchingStemRegex(
+ parentDir, stemRegex);
+
+ for (File f : matchingFileArray) {
+ f.delete();
+ }
+
+ if (parentClean) {
+ removeFolderIfEmpty(parentDir, 0);
+ }
+ }
+
+}
Modified: logback/trunk/logback-core/src/test/java/ch/qos/logback/core/rolling/PackageTest.java
==============================================================================
--- logback/trunk/logback-core/src/test/java/ch/qos/logback/core/rolling/PackageTest.java (original)
+++ logback/trunk/logback-core/src/test/java/ch/qos/logback/core/rolling/PackageTest.java Fri Aug 7 18:30:50 2009
@@ -5,7 +5,7 @@
@RunWith(Suite.class)
@Suite.SuiteClasses( { RenamingTest.class, SizeBasedRollingTest.class,
- TimeBasedRollingTest.class, TimeBasedRollingWithHistoryCleanTest.class,
+ TimeBasedRollingTest.class, TimeBasedRollingWithArchiveRemovalTest.class,
MultiThreadedRollingTest.class,
SizeAndTimeBasedFNATP_Test.class,
ch.qos.logback.core.rolling.helper.PackageTest.class })
Copied: logback/trunk/logback-core/src/test/java/ch/qos/logback/core/rolling/TimeBasedRollingWithArchiveRemovalTest.java (from r2418, /logback/trunk/logback-core/src/test/java/ch/qos/logback/core/rolling/TimeBasedRollingWithHistoryCleanTest.java)
==============================================================================
--- /logback/trunk/logback-core/src/test/java/ch/qos/logback/core/rolling/TimeBasedRollingWithHistoryCleanTest.java (original)
+++ logback/trunk/logback-core/src/test/java/ch/qos/logback/core/rolling/TimeBasedRollingWithArchiveRemovalTest.java Fri Aug 7 18:30:50 2009
@@ -3,7 +3,9 @@
import static org.junit.Assert.assertEquals;
import java.io.File;
-import java.io.FilenameFilter;
+import java.io.FileFilter;
+import java.util.ArrayList;
+import java.util.List;
import java.util.concurrent.TimeUnit;
import org.junit.After;
@@ -13,59 +15,117 @@
import ch.qos.logback.core.Context;
import ch.qos.logback.core.ContextBase;
import ch.qos.logback.core.layout.EchoLayout;
+import ch.qos.logback.core.testUtil.RandomUtil;
import ch.qos.logback.core.util.CoreTestConstants;
-public class TimeBasedRollingWithHistoryCleanTest {
+public class TimeBasedRollingWithArchiveRemovalTest {
Context context = new ContextBase();
EchoLayout<Object> layout = new EchoLayout<Object>();
static final String MONTHLY_DATE_PATTERN = "yyyy-MM";
+ static final String MONTHLY_CROLOLOG_DATE_PATTERN = "yyyy/MM";
+
static final String DAILY_DATE_PATTERN = "yyyy-MM-dd";
+ static final String DAILY_CROLOLOG_DATE_PATTERN = "yyyy/MM/dd";
static final long MILLIS_IN_MINUTE = 60 * 1000;
static final long MILLIS_IN_HOUR = 60 * MILLIS_IN_MINUTE;
static final long MILLIS_IN_DAY = 24 * MILLIS_IN_HOUR;
static final long MILLIS_IN_MONTH = 30 * MILLIS_IN_DAY;
+ int diff = RandomUtil.getPositiveInt();
+ protected String randomOutputDir = CoreTestConstants.OUTPUT_DIR_PREFIX + diff
+ + "/";
+ int slashCount;
+
+ // by default tbfnatp is an instance of
+ // DefaultTimeBasedFileNamingAndTriggeringPolicy
+ TimeBasedFileNamingAndTriggeringPolicy<Object> tbfnatp = new DefaultTimeBasedFileNamingAndTriggeringPolicy<Object>();
+
@Before
public void setUp() throws Exception {
context.setName("test");
-
- // remove all files containing the string 'clean'
- File dir = new File(CoreTestConstants.OUTPUT_DIR_PREFIX);
- if (dir.isDirectory()) {
- File[] toDelete = dir.listFiles(new FilenameFilter() {
- public boolean accept(File dir, String name) {
- return name.contains("clean");
- }
- });
- for (File f : toDelete) {
- System.out.println(f);
- f.delete();
- }
- }
}
@After
public void tearDown() throws Exception {
}
+ int computeSlashCount(String datePattern) {
+ int fromIndex = 0;
+ int count = 0;
+ while (true) {
+ int i = datePattern.indexOf('/', fromIndex);
+ if (i == -1) {
+ break;
+ } else {
+ count++;
+ fromIndex = i + 1;
+ if (fromIndex >= datePattern.length()) {
+ break;
+ }
+ }
+ }
+ return count;
+ }
+
@Test
public void montlyRollover() throws Exception {
- doRollover(CoreTestConstants.OUTPUT_DIR_PREFIX + "clean-%d{" + MONTHLY_DATE_PATTERN
- + "}.txt", MILLIS_IN_MONTH, 20);
+ slashCount = computeSlashCount(MONTHLY_DATE_PATTERN);
+ // large maxPeriod, a 3 times as many number of periods to simulate
+ doRollover(randomOutputDir + "clean-%d{" + MONTHLY_DATE_PATTERN + "}.txt",
+ MILLIS_IN_MONTH, 20, 20 * 3, expectedCountWithoutDirs(20));
+ }
+ @Test
+ public void montlyRolloverOverManyPeriods() throws Exception {
+ // small maxHistory, many periods
+ slashCount = computeSlashCount(MONTHLY_CROLOLOG_DATE_PATTERN);
+ doRollover(randomOutputDir + "/%d{" + MONTHLY_CROLOLOG_DATE_PATTERN
+ + "}/clean.txt.zip", MILLIS_IN_MONTH, 5, 40, expectedCountWithDirs(5));
}
@Test
public void dailyRollover() throws Exception {
- doRollover(CoreTestConstants.OUTPUT_DIR_PREFIX + "clean-%d{" + DAILY_DATE_PATTERN
- + "}.txt.zip", MILLIS_IN_DAY, 5);
+ slashCount = computeSlashCount(DAILY_DATE_PATTERN);
+ doRollover(
+ randomOutputDir + "clean-%d{" + DAILY_DATE_PATTERN + "}.txt.zip",
+ MILLIS_IN_DAY, 5, 5 * 3, expectedCountWithoutDirs(5));
}
- void doRollover(String fileNamePattern, long delay, int maxHistory)
- throws Exception {
+ @Test
+ public void dailyCronologRollover() throws Exception {
+ slashCount = computeSlashCount(DAILY_CROLOLOG_DATE_PATTERN);
+ doRollover(randomOutputDir + "/%d{" + DAILY_CROLOLOG_DATE_PATTERN
+ + "}/clean.txt.zip", MILLIS_IN_DAY, 8, 8 * 3, expectedCountWithDirs(8));
+ }
+
+ @Test
+ public void dailySizeBasedRollover() throws Exception {
+ SizeAndTimeBasedFNATP<Object> sizeAndTimeBasedFNATP = new SizeAndTimeBasedFNATP<Object>();
+ sizeAndTimeBasedFNATP.setMaxFileSize("1");
+ tbfnatp = sizeAndTimeBasedFNATP;
+
+ slashCount = computeSlashCount(DAILY_DATE_PATTERN);
+ doRollover(randomOutputDir + "/%d{" + DAILY_DATE_PATTERN
+ + "}-clean.%i.zip", MILLIS_IN_DAY, 5, 5 * 4, expectedCountWithoutDirs(5));
+ }
+
+
+ @Test
+ public void dailyChronologSizeBasedRollover() throws Exception {
+ SizeAndTimeBasedFNATP<Object> sizeAndTimeBasedFNATP = new SizeAndTimeBasedFNATP<Object>();
+ sizeAndTimeBasedFNATP.setMaxFileSize("1");
+ tbfnatp = sizeAndTimeBasedFNATP;
+
+ slashCount = computeSlashCount(DAILY_CROLOLOG_DATE_PATTERN);
+ doRollover(randomOutputDir + "/%d{" + DAILY_DATE_PATTERN
+ + "}/clean.%i.zip", MILLIS_IN_DAY, 5, 5 * 4, xexpectedCountWithDirs_NoSlash(5));
+ }
+
+ void doRollover(String fileNamePattern, long periodDurationInMillis,
+ int maxHistory, int simulatedNumberOfPeriods, int expectedCount) throws Exception {
long currentTime = System.currentTimeMillis();
RollingFileAppender<Object> rfa = new RollingFileAppender<Object>();
@@ -78,36 +138,71 @@
tbrp.setMaxHistory(maxHistory);
tbrp.setParent(rfa);
- tbrp.timeBasedTriggering = new DefaultTimeBasedFileNamingAndTriggeringPolicy<Object>();
+ tbrp.timeBasedTriggering = tbfnatp;
tbrp.timeBasedTriggering.setCurrentTime(currentTime);
tbrp.start();
rfa.setRollingPolicy(tbrp);
rfa.start();
- for (int i = 0; i < maxHistory * 3; i++) {
+ int ticksPerPeriod = 64;
+ long runLength = simulatedNumberOfPeriods * ticksPerPeriod;
+
+ for (long i = 0; i < runLength; i++) {
rfa.doAppend("Hello---" + i);
- tbrp.timeBasedTriggering.setCurrentTime(addTime(tbrp.timeBasedTriggering.getCurrentTime(), delay / 2));
+ tbrp.timeBasedTriggering.setCurrentTime(addTime(tbrp.timeBasedTriggering
+ .getCurrentTime(), periodDurationInMillis / ticksPerPeriod));
+
if (tbrp.future != null) {
tbrp.future.get(200, TimeUnit.MILLISECONDS);
}
}
rfa.stop();
- check(maxHistory + 1);
+ check(expectedCount);
}
- void check(int expectedCount) {
- // remove all files containing the string 'clean'
- File dir = new File(CoreTestConstants.OUTPUT_DIR_PREFIX);
+ void recursiveDirectoryDescent(File dir, List<File> fileList,
+ final String pattern) {
if (dir.isDirectory()) {
- File[] match = dir.listFiles(new FilenameFilter() {
- public boolean accept(File dir, String name) {
- return name.contains("clean");
+ File[] match = dir.listFiles(new FileFilter() {
+ public boolean accept(File f) {
+ if (f.isDirectory()) {
+ return true;
+ } else {
+ return f.getName().contains(pattern);
+ }
}
});
- //System.out.println(Arrays.toString(match));
- assertEquals(expectedCount, match.length);
+ for (File f : match) {
+ fileList.add(f);
+ if (f.isDirectory()) {
+ recursiveDirectoryDescent(f, fileList, pattern);
+ }
+ }
}
+ }
+ int expectedCountWithoutDirs(int maxHistory) {
+ // maxHistory plus the currently active file
+ return maxHistory+1;
+ }
+
+ int expectedCountWithDirs(int maxHistory) {
+ // each slash adds a new directory
+ // + one file and one directory per archived log file
+ return (maxHistory + 1) * 2 + slashCount;
+ }
+
+ int xexpectedCountWithDirs_NoSlash(int maxHistory) {
+ // each slash adds a new directory
+ // + one file and one directory per archived log file
+ return (maxHistory + 1) * 2;
+ }
+
+ void check(int expectedCount) {
+ File dir = new File(randomOutputDir);
+ List<File> fileList = new ArrayList<File>();
+ recursiveDirectoryDescent(dir, fileList, "clean");
+ assertEquals(expectedCount, fileList.size());
}
static long addTime(long currentTime, long timeToWait) {
Modified: logback/trunk/logback-core/src/test/java/ch/qos/logback/core/rolling/helper/DatePatternToRegexTest.java
==============================================================================
--- logback/trunk/logback-core/src/test/java/ch/qos/logback/core/rolling/helper/DatePatternToRegexTest.java (original)
+++ logback/trunk/logback-core/src/test/java/ch/qos/logback/core/rolling/helper/DatePatternToRegexTest.java Fri Aug 7 18:30:50 2009
@@ -46,10 +46,6 @@
doTest("yyyy-MMMM-dd", CAL_2009_08_3_NIGHT);
}
- @Test
- public void slash() {
- doTest("yyyy\\MMM\\dd", CAL_2009_08_3_NIGHT, true);
- }
@Test
public void dot() {
@@ -93,7 +89,7 @@
if(slashified) {
expected = expected.replace('\\', '/');
}
- String regex = dtc.toSRegex();
+ String regex = dtc.toRegex();
//System.out.println("expected="+expected);
//System.out.println(regex);
assertTrue("[" + expected + "] does not match regex [" + regex + "]",
Modified: logback/trunk/logback-core/src/test/java/ch/qos/logback/core/rolling/helper/FileNamePatternTest.java
==============================================================================
--- logback/trunk/logback-core/src/test/java/ch/qos/logback/core/rolling/helper/FileNamePatternTest.java (original)
+++ logback/trunk/logback-core/src/test/java/ch/qos/logback/core/rolling/helper/FileNamePatternTest.java Fri Aug 7 18:30:50 2009
@@ -28,19 +28,12 @@
@Test
public void testSmoke() {
- // System.out.println("Testing [t]");
FileNamePattern pp = new FileNamePattern("t", context);
assertEquals("t", pp.convertInt(3));
- // System.out.println("Testing [foo]");
pp = new FileNamePattern("foo", context);
assertEquals("foo", pp.convertInt(3));
- // System.out.println("Testing [foo%]");
- // pp = new FileNamePattern("foo%", context);
- // StatusPrinter.print(context.getStatusManager());
- // assertEquals("foo%", pp.convertInt(3));
-
pp = new FileNamePattern("%i foo", context);
assertEquals("3 foo", pp.convertInt(3));
@@ -54,11 +47,11 @@
pp = new FileNamePattern("foo.%i.log", context);
assertEquals("foo.3.log", pp.convertInt(3));
- pp = new FileNamePattern("%i.foo\\%", context);
- assertEquals("3.foo%", pp.convertInt(3));
+ //pp = new FileNamePattern("%i.foo\\%", context);
+ //assertEquals("3.foo%", pp.convertInt(3));
- pp = new FileNamePattern("\\%foo", context);
- assertEquals("%foo", pp.convertInt(3));
+ //pp = new FileNamePattern("\\%foo", context);
+ //assertEquals("%foo", pp.convertInt(3));
}
@Test
@@ -94,7 +87,7 @@
@Test
public void withBackslash() {
FileNamePattern pp = new FileNamePattern("c:\\foo\\bar.%i", context);
- assertEquals("c:\\foo\\bar.3", pp.convertInt(3));
+ assertEquals("c:/foo/bar.3", pp.convertInt(3));
}
@Test
@@ -116,13 +109,13 @@
{
FileNamePattern fnp = new FileNamePattern("foo-%d{yyyy.MM.dd}-%i.txt",
context);
- String regex = fnp.toSRegex(cal.getTime());
+ String regex = fnp.toRegex(cal.getTime());
assertEquals("foo-2003.05.20-(\\d{1,2}).txt", regex);
}
{
FileNamePattern fnp = new FileNamePattern("\\toto\\foo-%d{yyyy\\MM\\dd}-%i.txt",
context);
- String regex = fnp.toSRegex(cal.getTime());
+ String regex = fnp.toRegex(cal.getTime());
assertEquals("/toto/foo-2003/05/20-(\\d{1,2}).txt", regex);
}
}
@@ -133,7 +126,7 @@
cal.set(2003, 4, 20, 17, 55);
FileNamePattern fnp = new FileNamePattern("foo-%d{yyyy.MM.dd}-%i.txt",
context);
- String regex = fnp.toSRegex();
+ String regex = fnp.toRegex();
assertEquals("foo-\\d{4}\\.\\d{2}\\.\\d{2}-\\d{1,2}.txt", regex);
}
1
0

svn commit: r2418 - in logback/trunk/logback-core/src: main/java/ch/qos/logback/core/rolling main/java/ch/qos/logback/core/rolling/helper test/java/ch/qos/logback/core/rolling test/java/ch/qos/logback/core/rolling/helper
by noreply.ceki@qos.ch 07 Aug '09
by noreply.ceki@qos.ch 07 Aug '09
07 Aug '09
Author: ceki
Date: Fri Aug 7 12:01:16 2009
New Revision: 2418
Added:
logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/helper/ArchiveRemover.java
logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/helper/DefaultArchiveRemover.java
- copied, changed from r2417, /logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/helper/TimeBasedCleaner.java
logback/trunk/logback-core/src/test/java/ch/qos/logback/core/rolling/TimeBasedRollingWithHistoryCleanTest.java
- copied, changed from r2417, /logback/trunk/logback-core/src/test/java/ch/qos/logback/core/rolling/TimeBasedRollingWithCleanTest.java
Removed:
logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/helper/TimeBasedCleaner.java
logback/trunk/logback-core/src/test/java/ch/qos/logback/core/rolling/TimeBasedRollingWithCleanTest.java
Modified:
logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/DefaultTimeBasedFileNamingAndTriggeringPolicy.java
logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/SizeAndTimeBasedFNATP.java
logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/TimeBasedFileNamingAndTriggeringPolicy.java
logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/TimeBasedFileNamingAndTriggeringPolicyBase.java
logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/TimeBasedRollingPolicy.java
logback/trunk/logback-core/src/test/java/ch/qos/logback/core/rolling/PackageTest.java
logback/trunk/logback-core/src/test/java/ch/qos/logback/core/rolling/helper/DatePatternToRegexTest.java
logback/trunk/logback-core/src/test/java/ch/qos/logback/core/rolling/helper/FileNamePatternTest.java
Log:
- The TimeBasedCleaner class was refactored into the ArchiverRemover interface and DefailtArchiverRemover class.
- Providing an archive cleaner is now a responsibility of any TimeBasedFileNamingAndTriggeringPolicy
Modified: logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/DefaultTimeBasedFileNamingAndTriggeringPolicy.java
==============================================================================
--- logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/DefaultTimeBasedFileNamingAndTriggeringPolicy.java (original)
+++ logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/DefaultTimeBasedFileNamingAndTriggeringPolicy.java Fri Aug 7 12:01:16 2009
@@ -12,6 +12,8 @@
import java.io.File;
import java.util.Date;
+import ch.qos.logback.core.rolling.helper.DefaultArchiveRemover;
+
/**
*
* @author Ceki Gülcü
@@ -20,15 +22,15 @@
*/
public class DefaultTimeBasedFileNamingAndTriggeringPolicy<E> extends TimeBasedFileNamingAndTriggeringPolicyBase<E> {
-
-
+
+
@Override
public void start() {
super.start();
+ archiveRemover = new DefaultArchiveRemover(tbrp.fileNamePattern, rc);
started = true;
}
-
public boolean isTriggeringEvent(File activeFile, final E event) {
long time = getCurrentTime();
if (time >= nextCheck) {
Modified: logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/SizeAndTimeBasedFNATP.java
==============================================================================
--- logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/SizeAndTimeBasedFNATP.java (original)
+++ logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/SizeAndTimeBasedFNATP.java Fri Aug 7 12:01:16 2009
@@ -102,5 +102,4 @@
this.maxFileSizeAsString = maxFileSize;
this.maxFileSize = FileSize.valueOf(maxFileSize);
}
-
}
Modified: logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/TimeBasedFileNamingAndTriggeringPolicy.java
==============================================================================
--- logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/TimeBasedFileNamingAndTriggeringPolicy.java (original)
+++ logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/TimeBasedFileNamingAndTriggeringPolicy.java Fri Aug 7 12:01:16 2009
@@ -12,7 +12,7 @@
import java.util.Date;
-import ch.qos.logback.core.rolling.helper.RollingCalendar;
+import ch.qos.logback.core.rolling.helper.ArchiveRemover;
import ch.qos.logback.core.spi.ContextAware;
/**
@@ -50,12 +50,10 @@
String getCurrentPeriodsFileNameWithoutCompressionSuffix();
/**
- * Return the rolling calendar used by this instance.
- *
- * @return
+ * Return the archive remover appropriate for this instance.
*/
- RollingCalendar getRollingCalendar();
-
+ public ArchiveRemover getArchiveRemover();
+
/**
* Return the current time which is usually the value returned by
* System.currentMillis(). However, for <b>testing</b> purposed this value
Modified: logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/TimeBasedFileNamingAndTriggeringPolicyBase.java
==============================================================================
--- logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/TimeBasedFileNamingAndTriggeringPolicyBase.java (original)
+++ logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/TimeBasedFileNamingAndTriggeringPolicyBase.java Fri Aug 7 12:01:16 2009
@@ -2,6 +2,7 @@
import java.util.Date;
+import ch.qos.logback.core.rolling.helper.ArchiveRemover;
import ch.qos.logback.core.rolling.helper.DateTokenConverter;
import ch.qos.logback.core.rolling.helper.RollingCalendar;
import ch.qos.logback.core.spi.ContextAwareBase;
@@ -11,7 +12,7 @@
protected TimeBasedRollingPolicy<E> tbrp;
-
+ protected ArchiveRemover archiveRemover = null;
protected String elapsedPeriodsFileName;
protected RollingCalendar rc;
@@ -21,7 +22,6 @@
protected boolean isTimeForced = false;
protected Date dateInCurrentPeriod = null;
-
protected long nextCheck;
protected boolean started = false;
@@ -104,8 +104,8 @@
}
- public RollingCalendar getRollingCalendar() {
- return rc;
+ public ArchiveRemover getArchiveRemover() {
+ return archiveRemover;
}
}
Modified: logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/TimeBasedRollingPolicy.java
==============================================================================
--- logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/TimeBasedRollingPolicy.java (original)
+++ logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/TimeBasedRollingPolicy.java Fri Aug 7 12:01:16 2009
@@ -14,12 +14,12 @@
import java.util.concurrent.Future;
import ch.qos.logback.core.CoreConstants;
+import ch.qos.logback.core.rolling.helper.ArchiveRemover;
import ch.qos.logback.core.rolling.helper.AsynchronousCompressor;
import ch.qos.logback.core.rolling.helper.CompressionMode;
import ch.qos.logback.core.rolling.helper.Compressor;
import ch.qos.logback.core.rolling.helper.FileNamePattern;
import ch.qos.logback.core.rolling.helper.RenameUtil;
-import ch.qos.logback.core.rolling.helper.TimeBasedCleaner;
/**
* <code>TimeBasedRollingPolicy</code> is both easy to configure and quite
@@ -38,15 +38,16 @@
// WCS: without compression suffix
FileNamePattern fileNamePatternWCS;
-
+
private Compressor compressor;
private RenameUtil renameUtil = new RenameUtil();
Future<?> future;
private int maxHistory = NO_DELETE_HISTORY;
- private TimeBasedCleaner tbCleaner;
+ private ArchiveRemover archiveRemover;
TimeBasedFileNamingAndTriggeringPolicy<E> timeBasedTriggering;
+
public void start() {
// set the LR for our utility object
renameUtil.setContext(this.context);
@@ -65,26 +66,30 @@
compressor = new Compressor(compressionMode);
compressor.setContext(context);
- fileNamePatternWCS = new FileNamePattern(computeFileNameStr_WCS(fileNamePatternStr,
- compressionMode), this.context);
+ fileNamePatternWCS = new FileNamePattern(computeFileNameStr_WCS(
+ fileNamePatternStr, compressionMode), this.context);
addInfo("Will use the pattern " + fileNamePatternWCS
+ " for the active file");
- if(timeBasedTriggering == null) {
+ if (timeBasedTriggering == null) {
timeBasedTriggering = new DefaultTimeBasedFileNamingAndTriggeringPolicy<E>();
}
timeBasedTriggering.setContext(context);
timeBasedTriggering.setTimeBasedRollingPolicy(this);
timeBasedTriggering.start();
+ // the maxHistory property is given to TimeBasedRollingPolicy instead of to
+ // the TimeBasedFileNamingAndTriggeringPolicy. This makes it more convenient
+ // for the user at the cost of inconsistency at the level of this code.
if (maxHistory != NO_DELETE_HISTORY) {
- tbCleaner = new TimeBasedCleaner(fileNamePattern, timeBasedTriggering.getRollingCalendar(),
- maxHistory);
+ archiveRemover = timeBasedTriggering.getArchiveRemover();
+ archiveRemover.setMaxHistory(maxHistory);
}
}
- public void setTimeBasedFileNamingAndTriggeringPolicy(TimeBasedFileNamingAndTriggeringPolicy<E> timeBasedTriggering) {
+ public void setTimeBasedFileNamingAndTriggeringPolicy(
+ TimeBasedFileNamingAndTriggeringPolicy<E> timeBasedTriggering) {
this.timeBasedTriggering = timeBasedTriggering;
}
@@ -92,7 +97,6 @@
return timeBasedTriggering;
}
-
static String computeFileNameStr_WCS(String fileNamePatternStr,
CompressionMode compressionMode) {
int len = fileNamePatternStr.length();
@@ -127,8 +131,8 @@
}
}
- if (tbCleaner != null) {
- tbCleaner.clean(new Date(timeBasedTriggering.getCurrentTime()));
+ if (archiveRemover != null) {
+ archiveRemover.clean(new Date(timeBasedTriggering.getCurrentTime()));
}
}
@@ -171,7 +175,8 @@
if (parentsRawFileProperty != null) {
return parentsRawFileProperty;
} else {
- return timeBasedTriggering.getCurrentPeriodsFileNameWithoutCompressionSuffix();
+ return timeBasedTriggering
+ .getCurrentPeriodsFileNameWithoutCompressionSuffix();
}
}
Added: logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/helper/ArchiveRemover.java
==============================================================================
--- (empty file)
+++ logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/helper/ArchiveRemover.java Fri Aug 7 12:01:16 2009
@@ -0,0 +1,22 @@
+/**
+ * Logback: the generic, reliable, fast and flexible logging framework.
+ *
+ * Copyright (C) 2000-2009, QOS.ch
+ *
+ * This library is free software, you can redistribute it and/or modify it under
+ * the terms of the GNU Lesser General Public License as published by the Free
+ * Software Foundation.
+ */
+package ch.qos.logback.core.rolling.helper;
+
+import java.util.Date;
+
+/**
+ * Given a date remove older archived log files.
+ *
+ * @author Ceki Gülcü
+ */
+public interface ArchiveRemover {
+ public void clean(Date now);
+ public void setMaxHistory(int maxHistory);
+}
\ No newline at end of file
Copied: logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/helper/DefaultArchiveRemover.java (from r2417, /logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/helper/TimeBasedCleaner.java)
==============================================================================
--- /logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/helper/TimeBasedCleaner.java (original)
+++ logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/helper/DefaultArchiveRemover.java Fri Aug 7 12:01:16 2009
@@ -13,22 +13,20 @@
import java.io.File;
import java.util.Date;
-public class TimeBasedCleaner {
+public class DefaultArchiveRemover implements ArchiveRemover {
FileNamePattern fileNamePattern;
RollingCalendar rc;
- int numberOfPeriods;
-
- public TimeBasedCleaner(FileNamePattern fileNamePattern, RollingCalendar rc,
- int numberOfPeriods) {
+ int maxHistory;
+ int periodOffset;
+
+ public DefaultArchiveRemover(FileNamePattern fileNamePattern, RollingCalendar rc) {
this.fileNamePattern = fileNamePattern;
this.rc = rc;
- //
- this.numberOfPeriods = -numberOfPeriods -1;
}
public void clean(Date now) {
- Date date2delete = rc.getRelativeDate(now, numberOfPeriods);
+ Date date2delete = rc.getRelativeDate(now, periodOffset);
String filename = fileNamePattern.convert(date2delete);
@@ -39,4 +37,9 @@
}
}
+ public void setMaxHistory(int maxHistory) {
+ this.maxHistory = maxHistory;
+ this.periodOffset = -maxHistory -1;
+ }
+
}
Modified: logback/trunk/logback-core/src/test/java/ch/qos/logback/core/rolling/PackageTest.java
==============================================================================
--- logback/trunk/logback-core/src/test/java/ch/qos/logback/core/rolling/PackageTest.java (original)
+++ logback/trunk/logback-core/src/test/java/ch/qos/logback/core/rolling/PackageTest.java Fri Aug 7 12:01:16 2009
@@ -5,7 +5,7 @@
@RunWith(Suite.class)
@Suite.SuiteClasses( { RenamingTest.class, SizeBasedRollingTest.class,
- TimeBasedRollingTest.class, TimeBasedRollingWithCleanTest.class,
+ TimeBasedRollingTest.class, TimeBasedRollingWithHistoryCleanTest.class,
MultiThreadedRollingTest.class,
SizeAndTimeBasedFNATP_Test.class,
ch.qos.logback.core.rolling.helper.PackageTest.class })
Copied: logback/trunk/logback-core/src/test/java/ch/qos/logback/core/rolling/TimeBasedRollingWithHistoryCleanTest.java (from r2417, /logback/trunk/logback-core/src/test/java/ch/qos/logback/core/rolling/TimeBasedRollingWithCleanTest.java)
==============================================================================
--- /logback/trunk/logback-core/src/test/java/ch/qos/logback/core/rolling/TimeBasedRollingWithCleanTest.java (original)
+++ logback/trunk/logback-core/src/test/java/ch/qos/logback/core/rolling/TimeBasedRollingWithHistoryCleanTest.java Fri Aug 7 12:01:16 2009
@@ -15,7 +15,7 @@
import ch.qos.logback.core.layout.EchoLayout;
import ch.qos.logback.core.util.CoreTestConstants;
-public class TimeBasedRollingWithCleanTest {
+public class TimeBasedRollingWithHistoryCleanTest {
Context context = new ContextBase();
EchoLayout<Object> layout = new EchoLayout<Object>();
Modified: logback/trunk/logback-core/src/test/java/ch/qos/logback/core/rolling/helper/DatePatternToRegexTest.java
==============================================================================
--- logback/trunk/logback-core/src/test/java/ch/qos/logback/core/rolling/helper/DatePatternToRegexTest.java (original)
+++ logback/trunk/logback-core/src/test/java/ch/qos/logback/core/rolling/helper/DatePatternToRegexTest.java Fri Aug 7 12:01:16 2009
@@ -95,7 +95,7 @@
}
String regex = dtc.toSRegex();
//System.out.println("expected="+expected);
- System.out.println(regex);
+ //System.out.println(regex);
assertTrue("[" + expected + "] does not match regex [" + regex + "]",
expected.matches(regex));
}
Modified: logback/trunk/logback-core/src/test/java/ch/qos/logback/core/rolling/helper/FileNamePatternTest.java
==============================================================================
--- logback/trunk/logback-core/src/test/java/ch/qos/logback/core/rolling/helper/FileNamePatternTest.java (original)
+++ logback/trunk/logback-core/src/test/java/ch/qos/logback/core/rolling/helper/FileNamePatternTest.java Fri Aug 7 12:01:16 2009
@@ -89,7 +89,7 @@
pp = new FileNamePattern("%d{yyyy.MM.dd HH:mm} foo", context);
assertEquals("2003.05.20 17:55 foo", pp.convert(cal.getTime()));
- }
+ }
@Test
public void withBackslash() {
1
0

svn commit: r2417 - in logback/trunk/logback-core/src: main/java/ch/qos/logback/core/rolling/helper test/java/ch/qos/logback/core/rolling/helper
by noreply.ceki@qos.ch 06 Aug '09
by noreply.ceki@qos.ch 06 Aug '09
06 Aug '09
Author: ceki
Date: Thu Aug 6 23:52:03 2009
New Revision: 2417
Modified:
logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/helper/FileFilterUtil.java
logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/helper/FileNamePattern.java
logback/trunk/logback-core/src/test/java/ch/qos/logback/core/rolling/helper/FileNamePatternTest.java
Log:
- all logback-core tests pass
Modified: logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/helper/FileFilterUtil.java
==============================================================================
--- logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/helper/FileFilterUtil.java (original)
+++ logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/helper/FileFilterUtil.java Thu Aug 6 23:52:03 2009
@@ -52,17 +52,20 @@
* Return the set of files matching the stemRegex as found in 'directory'. A
* stemRegex does not contain any slash characters or any folder seperators.
*
- * @param directory
+ * @param file
* @param stemRegex
* @return
*/
- public static File[] filesInFolderMatchingStemRegex(File directory,
+ public static File[] filesInFolderMatchingStemRegex(File file,
final String stemRegex) {
- if (directory == null || directory.isDirectory()) {
- throw new IllegalArgumentException("[" + directory
- + " cannot be null or a non-directory");
+
+ if (file == null) {
+ return new File[0];
+ }
+ if (!file.exists() || !file.isDirectory()) {
+ return new File[0];
}
- File[] matchingFileArray = directory.listFiles(new FilenameFilter() {
+ File[] matchingFileArray = file.listFiles(new FilenameFilter() {
public boolean accept(File dir, String name) {
return name.matches(stemRegex);
}
@@ -71,9 +74,9 @@
}
static public int extractCounter(File file, final String stemRegex) {
- Pattern p = Pattern.compile(stemRegex);
+ Pattern p = Pattern.compile(stemRegex);
String lastFileName = file.getName();
-
+
Matcher m = p.matcher(lastFileName);
if (!m.matches()) {
throw new IllegalStateException("The regex [" + stemRegex
Modified: logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/helper/FileNamePattern.java
==============================================================================
--- logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/helper/FileNamePattern.java (original)
+++ logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/helper/FileNamePattern.java Thu Aug 6 23:52:03 2009
@@ -154,7 +154,7 @@
} else if (p instanceof IntegerTokenConverter) {
buf.append("(\\d{1,2})");
} else if (p instanceof DateTokenConverter) {
- buf.append(p.convert(date));
+ buf.append(FileFilterUtil.slashify(p.convert(date)));
}
p = p.getNext();
}
Modified: logback/trunk/logback-core/src/test/java/ch/qos/logback/core/rolling/helper/FileNamePatternTest.java
==============================================================================
--- logback/trunk/logback-core/src/test/java/ch/qos/logback/core/rolling/helper/FileNamePatternTest.java (original)
+++ logback/trunk/logback-core/src/test/java/ch/qos/logback/core/rolling/helper/FileNamePatternTest.java Thu Aug 6 23:52:03 2009
@@ -117,13 +117,13 @@
FileNamePattern fnp = new FileNamePattern("foo-%d{yyyy.MM.dd}-%i.txt",
context);
String regex = fnp.toSRegex(cal.getTime());
- assertEquals("foo-2003.05.20-\\d{1,2}.txt", regex);
+ assertEquals("foo-2003.05.20-(\\d{1,2}).txt", regex);
}
{
FileNamePattern fnp = new FileNamePattern("\\toto\\foo-%d{yyyy\\MM\\dd}-%i.txt",
context);
String regex = fnp.toSRegex(cal.getTime());
- assertEquals("/toto/foo-2003/05/20-\\d{1,2}.txt", regex);
+ assertEquals("/toto/foo-2003/05/20-(\\d{1,2}).txt", regex);
}
}
1
0

svn commit: r2416 - in logback/trunk/logback-core/src: main/java/ch/qos/logback/core/rolling main/java/ch/qos/logback/core/rolling/helper test/java/ch/qos/logback/core/rolling
by noreply.ceki@qos.ch 06 Aug '09
by noreply.ceki@qos.ch 06 Aug '09
06 Aug '09
Author: ceki
Date: Thu Aug 6 23:34:46 2009
New Revision: 2416
Added:
logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/helper/FileFilterUtil.java
Modified:
logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/SizeAndTimeBasedFNATP.java
logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/helper/FileNamePattern.java
logback/trunk/logback-core/src/test/java/ch/qos/logback/core/rolling/ScaffoldingForRollingTests.java
logback/trunk/logback-core/src/test/java/ch/qos/logback/core/rolling/SizeAndTimeBasedFNATP_Test.java
Log:
- removed duplicate code as much as possible
Modified: logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/SizeAndTimeBasedFNATP.java
==============================================================================
--- logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/SizeAndTimeBasedFNATP.java (original)
+++ logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/SizeAndTimeBasedFNATP.java Thu Aug 6 23:34:46 2009
@@ -10,14 +10,10 @@
package ch.qos.logback.core.rolling;
import java.io.File;
-import java.io.FilenameFilter;
-import java.util.Arrays;
-import java.util.Comparator;
import java.util.Date;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
import ch.qos.logback.core.joran.spi.NoAutoStart;
+import ch.qos.logback.core.rolling.helper.FileFilterUtil;
import ch.qos.logback.core.util.FileSize;
@NoAutoStart
@@ -37,58 +33,26 @@
// we need to get the correct value of currentPeriodsCounter.
// usually the value is 0, unless the appender or the application
// is stopped and restarted within the same period
-
if (tbrp.getParentsRawFileProperty() == null) {
- String sregex = tbrp.fileNamePattern.toSRegex(dateInCurrentPeriod);
- String simplifiedRegex = afterLastSlash(sregex);
- computeCurrentPeriodsCounter(simplifiedRegex);
+ String slashifiedRegex = tbrp.fileNamePattern.toSRegex(dateInCurrentPeriod);
+ String stemRegex = FileFilterUtil.afterLastSlash(slashifiedRegex);
+ computeCurrentPeriodsHighestCounterValue(stemRegex);
}
started = true;
}
- String afterLastSlash(String sregex) {
- int i = sregex.lastIndexOf('/');
- if (i == -1) {
- return sregex;
- } else {
- return sregex.substring(i + 1);
- }
- }
-
- void computeCurrentPeriodsCounter(final String simplifiedRegex) {
+ void computeCurrentPeriodsHighestCounterValue(final String stemRegex) {
File file = new File(getCurrentPeriodsFileNameWithoutCompressionSuffix());
File parentDir = file.getParentFile();
- if (parentDir != null && parentDir.isDirectory()) {
- File[] matchingFileArray = parentDir.listFiles(new FilenameFilter() {
- public boolean accept(File dir, String name) {
- return name.matches(simplifiedRegex);
- }
- });
- if (matchingFileArray == null || matchingFileArray.length == 0) {
- return;
- }
- Arrays.sort(matchingFileArray, new Comparator<File>() {
- public int compare(File o1, File o2) {
- String o1Name = o1.getName();
- String o2Name = o2.getName();
- return (o2Name.compareTo(o1Name));
- }
- });
- File lastFile = matchingFileArray[0];
-
- Pattern p = Pattern.compile(simplifiedRegex);
- String lastFileName = lastFile.getName();
-
- Matcher m = p.matcher(lastFileName);
- if (!m.matches()) {
- throw new IllegalStateException("The regex [" + simplifiedRegex
- + "] should match [" + lastFileName + "]");
- }
- String currentPeriodsCounterAsStr = m.group(1);
- currentPeriodsCounter = new Integer(currentPeriodsCounterAsStr)
- .intValue();
+ File[] matchingFileArray = FileFilterUtil
+ .filesInFolderMatchingStemRegex(parentDir, stemRegex);
+
+ if (matchingFileArray == null || matchingFileArray.length == 0) {
+ return;
}
+ FileFilterUtil.reverseSortFileArrayByName(matchingFileArray);
+ currentPeriodsCounter = FileFilterUtil.extractCounter(matchingFileArray[0], stemRegex);
}
// IMPORTANT: This field can be updated by multiple threads. It follows that
Added: logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/helper/FileFilterUtil.java
==============================================================================
--- (empty file)
+++ logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/helper/FileFilterUtil.java Thu Aug 6 23:34:46 2009
@@ -0,0 +1,90 @@
+/**
+ * Logback: the generic, reliable, fast and flexible logging framework.
+ *
+ * Copyright (C) 2000-2009, QOS.ch
+ *
+ * This library is free software, you can redistribute it and/or modify it under
+ * the terms of the GNU Lesser General Public License as published by the Free
+ * Software Foundation.
+ */
+
+package ch.qos.logback.core.rolling.helper;
+
+import java.io.File;
+import java.io.FilenameFilter;
+import java.util.Arrays;
+import java.util.Comparator;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+public class FileFilterUtil {
+
+ public static void sortFileArrayByName(File[] fileArray) {
+ Arrays.sort(fileArray, new Comparator<File>() {
+ public int compare(File o1, File o2) {
+ String o1Name = o1.getName();
+ String o2Name = o2.getName();
+ return (o1Name.compareTo(o2Name));
+ }
+ });
+ }
+
+ public static void reverseSortFileArrayByName(File[] fileArray) {
+ Arrays.sort(fileArray, new Comparator<File>() {
+ public int compare(File o1, File o2) {
+ String o1Name = o1.getName();
+ String o2Name = o2.getName();
+ return (o2Name.compareTo(o1Name));
+ }
+ });
+ }
+
+ public static String afterLastSlash(String sregex) {
+ int i = sregex.lastIndexOf('/');
+ if (i == -1) {
+ return sregex;
+ } else {
+ return sregex.substring(i + 1);
+ }
+ }
+
+ /**
+ * Return the set of files matching the stemRegex as found in 'directory'. A
+ * stemRegex does not contain any slash characters or any folder seperators.
+ *
+ * @param directory
+ * @param stemRegex
+ * @return
+ */
+ public static File[] filesInFolderMatchingStemRegex(File directory,
+ final String stemRegex) {
+ if (directory == null || directory.isDirectory()) {
+ throw new IllegalArgumentException("[" + directory
+ + " cannot be null or a non-directory");
+ }
+ File[] matchingFileArray = directory.listFiles(new FilenameFilter() {
+ public boolean accept(File dir, String name) {
+ return name.matches(stemRegex);
+ }
+ });
+ return matchingFileArray;
+ }
+
+ static public int extractCounter(File file, final String stemRegex) {
+ Pattern p = Pattern.compile(stemRegex);
+ String lastFileName = file.getName();
+
+ Matcher m = p.matcher(lastFileName);
+ if (!m.matches()) {
+ throw new IllegalStateException("The regex [" + stemRegex
+ + "] should match [" + lastFileName + "]");
+ }
+ String counterAsStr = m.group(1);
+ int counter = new Integer(counterAsStr).intValue();
+ return counter;
+ }
+
+ static String slashify(String in) {
+ return in.replace('\\', '/');
+ }
+}
Modified: logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/helper/FileNamePattern.java
==============================================================================
--- logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/helper/FileNamePattern.java (original)
+++ logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/helper/FileNamePattern.java Thu Aug 6 23:34:46 2009
@@ -150,7 +150,7 @@
Converter<Object> p = headTokenConverter;
while (p != null) {
if (p instanceof LiteralConverter) {
- buf.append(slashify(p.convert(null)));
+ buf.append(FileFilterUtil.slashify(p.convert(null)));
} else if (p instanceof IntegerTokenConverter) {
buf.append("(\\d{1,2})");
} else if (p instanceof DateTokenConverter) {
@@ -161,10 +161,6 @@
return buf.toString();
}
- private String slashify(String in) {
- return in.replace('\\', '/');
- }
-
/**
* Given date, convert this instance to a slashified regular expression
*/
@@ -173,7 +169,7 @@
Converter<Object> p = headTokenConverter;
while (p != null) {
if (p instanceof LiteralConverter) {
- buf.append(slashify(p.convert(null)));
+ buf.append(FileFilterUtil.slashify(p.convert(null)));
} else if (p instanceof IntegerTokenConverter) {
buf.append("\\d{1,2}");
} else if (p instanceof DateTokenConverter) {
Modified: logback/trunk/logback-core/src/test/java/ch/qos/logback/core/rolling/ScaffoldingForRollingTests.java
==============================================================================
--- logback/trunk/logback-core/src/test/java/ch/qos/logback/core/rolling/ScaffoldingForRollingTests.java (original)
+++ logback/trunk/logback-core/src/test/java/ch/qos/logback/core/rolling/ScaffoldingForRollingTests.java Thu Aug 6 23:34:46 2009
@@ -17,14 +17,13 @@
import java.sql.Date;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
-import java.util.Arrays;
import java.util.Calendar;
-import java.util.Comparator;
import java.util.List;
import ch.qos.logback.core.Context;
import ch.qos.logback.core.ContextBase;
import ch.qos.logback.core.layout.EchoLayout;
+import ch.qos.logback.core.rolling.helper.FileFilterUtil;
import ch.qos.logback.core.testUtil.FileToBufferUtil;
import ch.qos.logback.core.testUtil.RandomUtil;
import ch.qos.logback.core.util.CoreTestConstants;
@@ -89,28 +88,14 @@
public static void sortedContentCheck(String outputDirStr, int runLength,
String prefix) throws IOException {
File[] fileArray = getFilesInDirectory(outputDirStr);
- Arrays.sort(fileArray, new Comparator<File>() {
- public int compare(File o1, File o2) {
- String o1Name = o1.getName();
- String o2Name = o2.getName();
- return (o1Name.compareTo(o2Name));
- }
- });
+ FileFilterUtil.sortFileArrayByName(fileArray);
fileContentCheck(fileArray, runLength, prefix);
}
public static void reverseSortedContentCheck(String outputDirStr,
int runLength, String prefix) throws IOException {
File[] fileArray = getFilesInDirectory(outputDirStr);
-
- Arrays.sort(fileArray, new Comparator<File>() {
- public int compare(File o1, File o2) {
- String o1Name = o1.getName();
- String o2Name = o2.getName();
- return (o2Name.compareTo(o1Name));
- }
- });
- System.out.println(Arrays.toString(fileArray));
+ FileFilterUtil.reverseSortFileArrayByName(fileArray);
fileContentCheck(fileArray, runLength, prefix);
}
Modified: logback/trunk/logback-core/src/test/java/ch/qos/logback/core/rolling/SizeAndTimeBasedFNATP_Test.java
==============================================================================
--- logback/trunk/logback-core/src/test/java/ch/qos/logback/core/rolling/SizeAndTimeBasedFNATP_Test.java (original)
+++ logback/trunk/logback-core/src/test/java/ch/qos/logback/core/rolling/SizeAndTimeBasedFNATP_Test.java Thu Aug 6 23:34:46 2009
@@ -16,7 +16,6 @@
import org.junit.Before;
import org.junit.Test;
-import ch.qos.logback.core.status.StatusChecker;
import ch.qos.logback.core.util.StatusPrinter;
public class SizeAndTimeBasedFNATP_Test extends
1
0