[logback-dev] [GIT] Logback: the generic, reliable, fast and flexible logging framework. branch, master, updated. 8fbef05787a8441839f32403a302296916a892b5
added by portage for gitosis-gentoo
git-noreply at pixie.qos.ch
Thu Aug 20 23:52:53 CEST 2009
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 8fbef05787a8441839f32403a302296916a892b5 (commit)
from 29f0061832915d56307bf0b82098092aa1fa3390 (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=8fbef05787a8441839f32403a302296916a892b5
http://github.com/ceki/logback/commit/8fbef05787a8441839f32403a302296916a892b5
commit 8fbef05787a8441839f32403a302296916a892b5
Author: Ceki Gulcu <ceki at qos.ch>
Date: Thu Aug 20 23:50:13 2009 +0200
- added documentation on ContextPropertyConverter
- added test cases in relation wit ContextPropertyConverter
diff --git a/logback-classic/src/main/java/ch/qos/logback/classic/PatternLayout.java b/logback-classic/src/main/java/ch/qos/logback/classic/PatternLayout.java
index 23bc4f8..84f2636 100644
--- a/logback-classic/src/main/java/ch/qos/logback/classic/PatternLayout.java
+++ b/logback-classic/src/main/java/ch/qos/logback/classic/PatternLayout.java
@@ -16,6 +16,7 @@ import ch.qos.logback.classic.joran.action.ContextNameAction;
import ch.qos.logback.classic.pattern.CallerDataConverter;
import ch.qos.logback.classic.pattern.ClassOfCallerConverter;
import ch.qos.logback.classic.pattern.ContextNameConverter;
+import ch.qos.logback.classic.pattern.ContextPropertyConverter;
import ch.qos.logback.classic.pattern.DateConverter;
import ch.qos.logback.classic.pattern.EnsureExceptionHandling;
import ch.qos.logback.classic.pattern.ExtendedThrowableProxyConverter;
@@ -114,6 +115,9 @@ public class PatternLayout extends PatternLayoutBase<ILoggingEvent> {
defaultConverterMap.put("marker", MarkerConverter.class.getName());
+ defaultConverterMap.put("property", ContextPropertyConverter.class.getName());
+
+
defaultConverterMap.put("n", LineSeparatorConverter.class.getName());
}
diff --git a/logback-classic/src/main/java/ch/qos/logback/classic/pattern/ContextPropertyConverter.java b/logback-classic/src/main/java/ch/qos/logback/classic/pattern/ContextPropertyConverter.java
index 3f9b0fe..7343317 100644
--- a/logback-classic/src/main/java/ch/qos/logback/classic/pattern/ContextPropertyConverter.java
+++ b/logback-classic/src/main/java/ch/qos/logback/classic/pattern/ContextPropertyConverter.java
@@ -16,23 +16,28 @@ import ch.qos.logback.classic.spi.LoggerContextVO;
public final class ContextPropertyConverter extends ClassicConverter {
- String propertyName;
+ String key;
public void start() {
String optStr = getFirstOption();
if (optStr != null) {
- propertyName = optStr;
+ key = optStr;
super.start();
}
}
public String convert(ILoggingEvent event) {
- if(propertyName == null) {
- return "ContextProperty_HAS_NO_NAME";
+ if (key == null) {
+ return "Property_HAS_NO_KEY";
} else {
LoggerContextVO lcvo = event.getLoggerContextVO();
Map<String, String> map = lcvo.getPropertyMap();
- return map.get(propertyName);
+ String val = map.get(key);
+ if (val != null) {
+ return val;
+ } else {
+ return System.getProperty(key);
+ }
}
}
}
diff --git a/logback-classic/src/test/java/ch/qos/logback/classic/PatternLayoutTest.java b/logback-classic/src/test/java/ch/qos/logback/classic/PatternLayoutTest.java
index 256fc60..a5f74b5 100644
--- a/logback-classic/src/test/java/ch/qos/logback/classic/PatternLayoutTest.java
+++ b/logback-classic/src/test/java/ch/qos/logback/classic/PatternLayoutTest.java
@@ -99,10 +99,18 @@ public class PatternLayoutTest extends AbstractPatternLayoutBaseTest {
String regex = ISO_REGEX
+ " c.q.l.c.p.ConverterTest - Some message\\s*";
assertTrue(val.matches(regex));
-
}
@Test
+ public void contextProperty() {
+ pl.setPattern("%property{a}");
+ pl.start();
+ lc.putProperty("a", "b");
+
+ String val = pl.doLayout(getEventObject());
+ assertEquals("b", val);
+ }
+ @Test
public void testNopExeptionHandler() {
pl.setPattern("%nopex %m%n");
pl.start();
diff --git a/logback-classic/src/test/java/ch/qos/logback/classic/pattern/ConverterTest.java b/logback-classic/src/test/java/ch/qos/logback/classic/pattern/ConverterTest.java
index 0524a71..147b066 100644
--- a/logback-classic/src/test/java/ch/qos/logback/classic/pattern/ConverterTest.java
+++ b/logback-classic/src/test/java/ch/qos/logback/classic/pattern/ConverterTest.java
@@ -359,4 +359,20 @@ public class ConverterTest {
String result = converter.convert(event);
assertEquals("aValue", result);
}
+
+ @Test
+ public void contextProperty() {
+ ContextPropertyConverter converter = new ContextPropertyConverter();
+ converter.setContext(lc);
+ List<String> ol = new ArrayList<String>();
+ ol.add("k");
+ converter.setOptionList(ol);
+ converter.start();
+ lc.setName("aValue");
+ lc.putProperty("k", "v");
+ ILoggingEvent event = makeLoggingEvent(null);
+
+ String result = converter.convert(event);
+ assertEquals("v", result);
+ }
}
diff --git a/logback-site/src/site/pages/manual/configuration.html b/logback-site/src/site/pages/manual/configuration.html
index 1f24aed..f725cf7 100644
--- a/logback-site/src/site/pages/manual/configuration.html
+++ b/logback-site/src/site/pages/manual/configuration.html
@@ -1150,6 +1150,14 @@ public class MyApp3 {
<em>${java.home.dir}</em> will be interpreted as <em>/home/xyz</em>.
</p>
+ <h4>properties are inserted into the logger context</h4>
+
+ <p>Note that the values defined via <code><property></code>
+ element are actually inserted into the logger context. In other
+ words, they become properties of the logger context. Consequently,
+ they will be available in all logging events as well as remotely
+ after serialization.</p>
+
<p>The next example shows a variable, a.k.a. a substitution
property, declared the beginning of the configuration file. It is
then used further down the file to specify the location of the
diff --git a/logback-site/src/site/pages/manual/layouts.html b/logback-site/src/site/pages/manual/layouts.html
index f2e91a4..044c84a 100644
--- a/logback-site/src/site/pages/manual/layouts.html
+++ b/logback-site/src/site/pages/manual/layouts.html
@@ -909,6 +909,29 @@ Caller+2 at mainPackage.ConfigTester.main(ConfigTester.java:38)</div>
</td>
</tr>
+
+ <tr>
+ <td align="center">
+ <b>property{key}</b>
+ </td>
+
+ <td>
+ <p >Used to output the value associated with a context
+ property named <em>key</em>. If <em>key</em> is not a
+ property of the logger context, then <em>key</em> will be
+ looked up in the System properties. </p>
+
+
+ <p>There is no default value for <em>key</em>. If it is
+ omitted, the returned value will be "Property_HAS_NO_KEY",
+ expliciting the error condition.</p>
+
+ <p>
+ </p>
+
+ </td>
+ </tr>
+
</table>
<p>Given that in the context of conversion patterns the percent
-----------------------------------------------------------------------
Summary of changes:
.../java/ch/qos/logback/classic/PatternLayout.java | 4 +++
.../classic/pattern/ContextPropertyConverter.java | 15 ++++++++----
.../ch/qos/logback/classic/PatternLayoutTest.java | 10 +++++++-
.../qos/logback/classic/pattern/ConverterTest.java | 16 +++++++++++++
.../src/site/pages/manual/configuration.html | 8 +++++++
logback-site/src/site/pages/manual/layouts.html | 23 ++++++++++++++++++++
6 files changed, 70 insertions(+), 6 deletions(-)
hooks/post-receive
--
Logback: the generic, reliable, fast and flexible logging framework.
More information about the logback-dev
mailing list