[logback-dev] [GIT] Logback: the generic, reliable, fast and flexible logging framework. branch, master, updated. v_0.9.27-12-g2023340
added by portage for gitosis-gentoo
git-noreply at pixie.qos.ch
Mon Jan 17 21:07:37 CET 2011
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "Logback: the generic, reliable, fast and flexible logging framework.".
The branch, master has been updated
via 20233406053eb9803270621f59386f9602827dba (commit)
from af3d5737f6caae2471a3881d6c9c14191c71d4ed (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
http://git.qos.ch/gitweb/?p=logback.git;a=commit;h=20233406053eb9803270621f59386f9602827dba
http://github.com/ceki/logback/commit/20233406053eb9803270621f59386f9602827dba
commit 20233406053eb9803270621f59386f9602827dba
Author: Ceki Gulcu <ceki at qos.ch>
Date: Mon Jan 17 21:02:40 2011 +0100
- renamed context bithTime property as birthTime
- added support for timeReference attribute in the the timestamp element in config files (XML and Groovy)
diff --git a/logback-classic/src/main/groovy/ch/qos/logback/classic/gaffer/ConfigurationDelegate.groovy b/logback-classic/src/main/groovy/ch/qos/logback/classic/gaffer/ConfigurationDelegate.groovy
index 8feb3cd..8193d52 100644
--- a/logback-classic/src/main/groovy/ch/qos/logback/classic/gaffer/ConfigurationDelegate.groovy
+++ b/logback-classic/src/main/groovy/ch/qos/logback/classic/gaffer/ConfigurationDelegate.groovy
@@ -29,7 +29,8 @@ import ch.qos.logback.core.status.StatusListener
import java.text.SimpleDateFormat
import ch.qos.logback.classic.turbo.TurboFilter
import ch.qos.logback.core.CoreConstants
-import ch.qos.logback.core.util.ContextUtil;
+import ch.qos.logback.core.util.ContextUtil
+import ch.qos.logback.core.joran.action.TimestampAction;
/**
* @author Ceki Gücü
@@ -156,9 +157,18 @@ public class ConfigurationDelegate extends ContextAwareBase {
context.addTurboFilter(turboFilter)
}
- String timestamp(String datePattern) {
+ String timestamp(String datePattern, long timeReference = -1) {
+ Date reference = null;
+
+ if(timeReference == -1) {
+ addInfo("Using current interpretation time, i.e. now, as time reference.");
+ reference = new Date()
+ } else {
+ reference = new Date(timeReference)
+ addInfo("Using " + reference +" as time reference.");
+ }
SimpleDateFormat sdf = new SimpleDateFormat(datePattern);
- sdf.format(new Date());
+ sdf.format(reference)
}
}
diff --git a/logback-classic/src/main/java/ch/qos/logback/classic/spi/LoggerContextVO.java b/logback-classic/src/main/java/ch/qos/logback/classic/spi/LoggerContextVO.java
index 5289051..d2c2e36 100644
--- a/logback-classic/src/main/java/ch/qos/logback/classic/spi/LoggerContextVO.java
+++ b/logback-classic/src/main/java/ch/qos/logback/classic/spi/LoggerContextVO.java
@@ -44,7 +44,7 @@ public class LoggerContextVO implements Serializable {
public LoggerContextVO(LoggerContext lc) {
this.name = lc.getName();
this.propertyMap = lc.getCopyOfPropertyMap();
- this.birthTime = lc.getBithTime();
+ this.birthTime = lc.getBirthTime();
}
public String getName() {
diff --git a/logback-classic/src/test/groovy/ch/qos/logback/classic/gaffer/ConfigurationDelegateTest.groovy b/logback-classic/src/test/groovy/ch/qos/logback/classic/gaffer/ConfigurationDelegateTest.groovy
index 2e5d65f..427d743 100644
--- a/logback-classic/src/test/groovy/ch/qos/logback/classic/gaffer/ConfigurationDelegateTest.groovy
+++ b/logback-classic/src/test/groovy/ch/qos/logback/classic/gaffer/ConfigurationDelegateTest.groovy
@@ -22,6 +22,7 @@ import ch.qos.logback.core.rolling.TimeBasedRollingPolicy
import ch.qos.logback.classic.encoder.PatternLayoutEncoder
import ch.qos.logback.core.util.CoreTestConstants
import ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP
+import ch.qos.logback.core.joran.action.TimestampAction
/**
* @author Ceki Gücü
@@ -66,6 +67,13 @@ class ConfigurationDelegateTest {
assertEquals(year.toString(), result)
}
+ @Test
+ void timestampWithContextBirthAsReference() {
+ String result = configurationDelegate.timestamp("yyyy", context.birthTime)
+ long year = Calendar.getInstance().get(Calendar.YEAR);
+ assertEquals(year.toString(), result)
+ }
+
@Test
void loggerWithoutName() {
diff --git a/logback-core/src/main/java/ch/qos/logback/core/Context.java b/logback-core/src/main/java/ch/qos/logback/core/Context.java
index d348f30..c750620 100644
--- a/logback-core/src/main/java/ch/qos/logback/core/Context.java
+++ b/logback-core/src/main/java/ch/qos/logback/core/Context.java
@@ -95,7 +95,7 @@ public interface Context extends PropertyContainer {
*
* @return The time as measured when this class was created.
*/
- public long getBithTime();
+ public long getBirthTime();
/**
* Object used for synchronization purposes.
diff --git a/logback-core/src/main/java/ch/qos/logback/core/ContextBase.java b/logback-core/src/main/java/ch/qos/logback/core/ContextBase.java
index f811400..b091759 100644
--- a/logback-core/src/main/java/ch/qos/logback/core/ContextBase.java
+++ b/logback-core/src/main/java/ch/qos/logback/core/ContextBase.java
@@ -118,7 +118,7 @@ public class ContextBase implements Context {
}
}
- public long getBithTime() {
+ public long getBirthTime() {
return birthTime;
}
diff --git a/logback-core/src/main/java/ch/qos/logback/core/joran/action/TimestampAction.java b/logback-core/src/main/java/ch/qos/logback/core/joran/action/TimestampAction.java
index 6c1ad3a..d252773 100644
--- a/logback-core/src/main/java/ch/qos/logback/core/joran/action/TimestampAction.java
+++ b/logback-core/src/main/java/ch/qos/logback/core/joran/action/TimestampAction.java
@@ -32,6 +32,8 @@ import ch.qos.logback.core.util.OptionHelper;
*/
public class TimestampAction extends Action {
static String DATE_PATTERN_ATTRIBUTE = "datePattern";
+ static String TIME_REFERENCE_ATTRIBUTE = "timeReference";
+ static String CONTEXT_BIRTH = "contextBirth";
boolean inError = false;
@@ -40,7 +42,7 @@ public class TimestampAction extends Action {
throws ActionException {
String keyStr = attributes.getValue(KEY_ATTRIBUTE);
if (OptionHelper.isEmpty(keyStr)) {
- addError("Attrubute named [" + KEY_ATTRIBUTE + "] cannot be empty");
+ addError("Attribute named [" + KEY_ATTRIBUTE + "] cannot be empty");
inError = true;
}
String datePatternStr = attributes.getValue(DATE_PATTERN_ATTRIBUTE);
@@ -50,11 +52,22 @@ public class TimestampAction extends Action {
inError = true;
}
+ String timeReferenceStr = attributes.getValue(TIME_REFERENCE_ATTRIBUTE);
+ Date timeReference = null;
+ if (CONTEXT_BIRTH.equalsIgnoreCase(timeReferenceStr)) {
+ addInfo("Using context birth as time reference.");
+ timeReference = new Date(context.getBirthTime());
+ } else {
+ timeReference = new Date();
+ addInfo("Using current interpretation time, i.e. now, as time reference.");
+ }
+
+
if (inError)
return;
SimpleDateFormat sdf = new SimpleDateFormat(datePatternStr);
- String val = sdf.format(new Date());
+ String val = sdf.format(timeReference);
addInfo("Adding property to the context with key=\"" + keyStr
+ "\" and value=\"" + val + "\" to the context");
diff --git a/logback-site/src/site/pages/manual/appenders.html b/logback-site/src/site/pages/manual/appenders.html
index a71913d..e7d6d4a 100644
--- a/logback-site/src/site/pages/manual/appenders.html
+++ b/logback-site/src/site/pages/manual/appenders.html
@@ -546,23 +546,47 @@ public interface Appender<E> extends LifeCycle, ContextAware, FilterAttachabl
</configuration></pre>
- <p>The timestamp element takes two attributes <span
- class="attr">key</span> and <span
- class="attr">datePattern</span>. The <span class="attr">key</span>
- attribute is the name of the key under which the timestamp will be
- available to subsequent configuration elements <a
+ <p>The timestamp element takes two mandatory attributes <span
+ class="attr">key</span> and <span class="attr">datePattern</span>
+ and an optional <span class="attr">timeReference</span>
+ attribute. The <span class="attr">key</span> attribute is the name
+ of the key under which the timestamp will be available to
+ subsequent configuration elements <a
href="configuration.html#variableSubstitution">as a
variable</a>. The <span class="attr">datePattern</span> attribute
denotes the date pattern used to convert the current time (at which
the configuration file is parsed) into a string. The date pattern
should follow the conventions defined in <a
- href="http://java.sun.com/j2se/1.4.2/docs/api/java/text/SimpleDateFormat.html">SimpleDateFormat</a>.
+ href="http://java.sun.com/j2se/1.4.2/docs/api/java/text/SimpleDateFormat.html">SimpleDateFormat</a>. The
+ <span class="attr">timeReference</span> attribute denotes the time
+ reference for the time stamp. The default is the
+ interpretation/parsing time of the configuration file, i.e. the
+ current time. However, under certain circumstances it might be
+ useful to use the context birth time as time reference. This can be
+ accomplished by setting the <span class="attr">timeReference</span>
+ attribute to <code>"contextBirth"</code>.
</p>
- <p>Experiment with by running the command:</p>
+ <p>Experiment with the <code><timestamp></code> element by
+ running the command:</p>
<p class="command">java chapters.appenders.ConfigurationTester src/main/java/chapters/appenders/conf/logback-timestamp.xml</p>
+ <p>To use the logger context birth date as time reference, you
+ would set the <span class="attr">timeReference</span> attribute to
+ "contextBirth" as shown below.</p>
+
+
+ <p class="example">Example: Timestamp using context birth date as time reference
+ (logback-examples/src/main/java/chapters/appenders/conf/logback-timestamp-contextBirth.xml)</p>
+
+ <span class="asGroovy" onclick="return asGroovy('logback-timestamp-contextBirth');">View as .groovy</span>
+ <pre id="logback-timestamp-contextBirth" class="prettyprint source"><configuration>
+ <timestamp key="bySecond" datePattern="yyyyMMdd'T'HHmmss"
+ <b>timeReference="contextBirth"</b>/>
+ ...
+</configuration></pre>
+
<h2>
<a name="RollingFileAppender" href="#RollingFileAppender">RollingFileAppender</a>
</h2>
diff --git a/logback-site/src/site/pages/manual/groovy.html b/logback-site/src/site/pages/manual/groovy.html
index 8e06a19..e7fba36 100644
--- a/logback-site/src/site/pages/manual/groovy.html
+++ b/logback-site/src/site/pages/manual/groovy.html
@@ -216,18 +216,24 @@ root(DEBUG, ["FILE"])</pre>
<!-- ========================================================== -->
- <h3>• <span class="code">timestamp(String datePattern)</span></h3>
+ <h3>• <span class="code">timestamp(String datePattern, long timeReference = -1)</span></h3>
<p>The <code>timestamp()</code> method method returns a string
- corresponding to the current time formatted according to the
- <code>datePattern</code> passed as a parameter. The datePattern
- parameter should follow the conventions defined by <a
- href="http://java.sun.com/j2se/1.4.2/docs/api/java/text/SimpleDateFormat.html">SimpleDateFormat</a>.
+ corresponding to the <code>timeReference</code> parameter
+ formatted according to the <code>datePattern</code> parameter. The
+ <code>datePattern</code> parameter should follow the conventions
+ defined by <a
+ href="http://java.sun.com/j2se/1.4.2/docs/api/java/text/SimpleDateFormat.html">SimpleDateFormat</a>. If
+ the <code>timeReference</code> value is unspecified, it defaults
+ to -1, in which case current time, that is time when the
+ configuration file is parsed, is used as the time
+ reference. Depending on the circumstances, occasion, you might
+ wish to use <code>context.birthTime</code> as the time reference.
</p>
<p>In the next example, the <code>bySecond</code> variable is
assigned the current time in the "yyyyMMdd'T'HHmmss" format. The
- bySecond variable is then used to define the value of the <span
+ "bySecond" variable is then used to define the value of the <span
class="option">file</span> property.
</p>
diff --git a/logback-site/src/site/pages/news.html b/logback-site/src/site/pages/news.html
index 57a55fb..fd6ee67 100644
--- a/logback-site/src/site/pages/news.html
+++ b/logback-site/src/site/pages/news.html
@@ -30,6 +30,21 @@
<h3>January xx, 2011 - Release of version 0.9.28</h3>
+ <div style="border: 1px solid #F44; background-color: #FED; padding-left: 1ex; padding-right: 1ex;">
+
+ <h4>Breaking change: In the Context interface, the previously
+ misspelled property <code>bithTime</code> is now renamed as
+ <code>birthTime</code>.</h4>
+
+ <p>In the <a
+ href="apidocs/ch/qos/logback/core/Context.html">Context</a>
+ interface, the previously misspelled property
+ <code>bithTime</code> ia now renamed as
+ <code>birthTime</code>. This is a backward-incompatible
+ change. All pre-existing references to "bithTime" property now
+ need to referenced as "birthTime".</p>
+ </div>
+
<p>Fixed <a href="http://jira.qos.ch/browse/LBCLASSIC-238">issue
238</a> reported by Robert Elliot. <code>GEventEvaluator</code>'s
start method now correctly sets the state of the instance.
@@ -40,6 +55,11 @@
href="http://jira.qos.ch/browse/LBCLASSIC-239">LBCLASSIC-239</a>
reported by Artyom Kalita.</p>
+ <p>It is now possible to use the context birth time as the time
+ reference for the <a
+ href="manual/appenders.html#uniquelyNamed"><code><timestamp></code></a>
+ element in configuration files.</p>
+
<hr width="80%" align="center" />
<h3>December 22nd, 2010 - Release of version 0.9.27</h3>
-----------------------------------------------------------------------
Summary of changes:
.../classic/gaffer/ConfigurationDelegate.groovy | 16 +++++++--
.../qos/logback/classic/spi/LoggerContextVO.java | 2 +-
.../gaffer/ConfigurationDelegateTest.groovy | 8 ++++
.../src/main/java/ch/qos/logback/core/Context.java | 2 +-
.../main/java/ch/qos/logback/core/ContextBase.java | 2 +-
.../logback/core/joran/action/TimestampAction.java | 17 ++++++++-
logback-site/src/site/pages/manual/appenders.html | 38 ++++++++++++++++----
logback-site/src/site/pages/manual/groovy.html | 18 ++++++---
logback-site/src/site/pages/news.html | 20 ++++++++++
9 files changed, 102 insertions(+), 21 deletions(-)
hooks/post-receive
--
Logback: the generic, reliable, fast and flexible logging framework.
More information about the logback-dev
mailing list