Skip to content

Commit

Permalink
allow timeout to be specified as a duration
Browse files Browse the repository at this point in the history
  • Loading branch information
ceki committed Apr 26, 2013
1 parent 278d8d4 commit 54b6fdd
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 20 deletions.
2 changes: 1 addition & 1 deletion logback-classic/src/test/input/joran/sift/timeout.xml
Expand Up @@ -9,7 +9,7 @@
<key>timeout</key>
<defaultValue>smoke</defaultValue>
</discriminator>
<timeout>30000</timeout>
<timeout>30 seconds</timeout>
<sift>
<appender name="list-${userid}"
class="ch.qos.logback.core.read.ListAppender"/>
Expand Down
Expand Up @@ -15,6 +15,7 @@

import ch.qos.logback.core.Appender;
import ch.qos.logback.core.AppenderBase;
import ch.qos.logback.core.util.Duration;

/**
* This appender serves as the base class for actual SiftingAppenders
Expand All @@ -31,16 +32,16 @@ public abstract class SiftingAppenderBase<E> extends

protected AppenderTracker<E> appenderTracker;
AppenderFactory<E> appenderFactory;
int timeout = AppenderTracker.DEFAULT_TIMEOUT;
Duration timeout = new Duration(AppenderTracker.DEFAULT_TIMEOUT);
int maxAppenderCount = AppenderTracker.DEFAULT_MAX_COMPONENTS;

Discriminator<E> discriminator;

public int getTimeout() {
public Duration getTimeout() {
return timeout;
}

public void setTimeout(int timeout) {
public void setTimeout(Duration timeout) {
this.timeout = timeout;
}

Expand Down Expand Up @@ -77,7 +78,7 @@ public void start() {
} else {
appenderTracker = new AppenderTracker<E>(context, appenderFactory);
appenderTracker.setMaxComponents(maxAppenderCount);
appenderTracker.setTimeout(timeout);
appenderTracker.setTimeout(timeout.getMilliseconds());
}
if (errors == 0) {
super.start();
Expand Down
Expand Up @@ -18,14 +18,13 @@

/**
* Duration instances represent a lapse of time. Internally, the duration is
* stored in milliseconds.
* <p>
*
* The {@link #valueOf} method can convert strings such as "3.5 minutes", "5
* hours", into Duration instances. The recognized units of time are the
* "millisecond", "second", "minute" "hour" and "day". The unit name may be
* followed by an "s". Thus, "2 day" and "2 days" are equivalent. In the absence
* of a time unit specification, milliseconds are assumed.
* stored in milliseconds. This class follows the {@link #valueOf} convention meaning that it can
* convert an appropriately formatted string into a Duration object.
*
* <p>For example, string such as "3.5 minutes" or "5 hours" can be converted into Durations.
* The recognized units of time are the "millisecond", "second", "minute" "hour" and "day".
* The unit name may be followed by an "s". Thus, "2 day" and "2 days" are equivalent. In the
* absence of a time unit specification, milliseconds are assumed.
*
*
* @author Ceki Gulcu
Expand Down
34 changes: 31 additions & 3 deletions logback-site/src/site/pages/manual/appenders.html
Expand Up @@ -3642,15 +3642,43 @@ <h3 class="doAnchor" name="SiftingAppender">SiftingAppender</h3>
</p>



<table class="bodyTable striped">
<tr>
<th>Property Name</th>
<th>Type</th>
<th>Description</th>
</tr>
<tr>
<td><span class="prop" container="sift">timeout</span></td>
<td><code><a href="../apidocs/ch/qos/logback/core/util/Duration.html">Duration</a></code></td>
<td>A nested appender which has not been accessed beyond the
<span class="prop">timeout</span> duration is deemed stale. A
stale appender is closed and unreferenced by
<code>SiftingAppender</code>. The dfault value for <span
class="prop">timeout</span> is 30 minutes.</td>
</tr>
<tr>
<td><span class="prop" container="sift">maxAppenderCount</span></td>
<td><code>integer</code></td>
<td>The maximum number of nested appenders
<code>SiftingAppender</code> may create and track. Default
value for <span class="prop">maxAppenderCount</span> is
Integer.MAX_VALUE.</td>
</tr>
</table>

<p><code>SiftingAppender</code> achieves this feat by creating
child appenders on the fly. Child appenders are created based on a
template specified within the configuration of the
nested appenders on the fly. Nested appenders are created based on
a template specified within the configuration of the
<code>SiftingAppender</code> itself (enclosed within the
<code>&lt;sift></code> element, see example
below). <code>SiftingAppender</code> is responsible for managing
the lifecycle of child appenders. For example,
<code>SiftingAppender</code> will automatically close and remove
any unused child appender.
any stale appender. A nested appender is considered stale when no
accesses it beyond the duration specified by the <span
class="prop">timeout</span> parameter.
</p>

<p>When handling a logging event, <code>SiftingAppender</code>
Expand Down
13 changes: 9 additions & 4 deletions logback-site/src/site/pages/news.html
Expand Up @@ -64,7 +64,6 @@ <h3>April, 2013 - Release of version 1.0.12</h3>
<a href="manual/appenders.html#serverSocketAppender">ServerSocketAppender</a>
for information on configuring appenders as event sources for
receiver components.</p>


<p><code>RollingFileAppender</code> will now detect when <span
class="option">file</span> property collides with <span
Expand Down Expand Up @@ -95,15 +94,21 @@ <h3>April, 2013 - Release of version 1.0.12</h3>
<p class="highlight">Groovy configurator no longer supports
SiftingAppender.</p>

<p>Component tracking code has been simplified and completely
re-written. As a result of these changes, the groovy configurator
<p>In response to <a
href="http://jira.qos.ch/browse/LOGBACK-244">LOGBACK-244</a>, <a
href="http://jira.qos.ch/browse/LOGBACK-724">LOGBACK-724</a> and
in particular patches provided by Tommy Becker and David Roussel
component tracking code has been simplified and completely
re-written. SiftingAppender now supports timeout and
maxAppenderCount parameter. As a direct consequence of
modificatons to component tracking code, the groovy configurator
no longer supports <code>SiftingAppender</code>.</p>

<p>SiftingAppender now propagates properties defined elsewhere in
the configuration file into the configuration process of nested
appenders. This fixes <a
href="http://jira.qos.ch/browse/LOGBACK-833">LOGBACK-833</a> with
David Roussel providing the appropriate patch..
David Roussel providing the appropriate patch.
</p>

<p>As all other actions affecting properties,
Expand Down

0 comments on commit 54b6fdd

Please sign in to comment.