[logback-dev] [GIT] Logback: the generic, reliable, fast and flexible logging framework. branch, master, updated. release_0.9.19-7-g199e8d6
added by portage for gitosis-gentoo
git-noreply at pixie.qos.ch
Mon Mar 29 22:56:22 CEST 2010
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 199e8d6d8218c1bf526c224e867891110ac0ecbb (commit)
from 2391b73837b528d78505a0b3a339b533b791d283 (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=199e8d6d8218c1bf526c224e867891110ac0ecbb
http://github.com/ceki/logback/commit/199e8d6d8218c1bf526c224e867891110ac0ecbb
commit 199e8d6d8218c1bf526c224e867891110ac0ecbb
Author: Ceki Gulcu <ceki at qos.ch>
Date: Mon Mar 29 22:54:58 2010 +0200
- initial impl of if-then-else support in logback-classes
diff --git a/logback-classic/src/main/java/ch/qos/logback/classic/joran/JoranConfigurator.java b/logback-classic/src/main/java/ch/qos/logback/classic/joran/JoranConfigurator.java
index 9bc0624..765498a 100644
--- a/logback-classic/src/main/java/ch/qos/logback/classic/joran/JoranConfigurator.java
+++ b/logback-classic/src/main/java/ch/qos/logback/classic/joran/JoranConfigurator.java
@@ -29,6 +29,9 @@ import ch.qos.logback.core.joran.JoranConfiguratorBase;
import ch.qos.logback.core.joran.action.AppenderRefAction;
import ch.qos.logback.core.joran.action.IncludeAction;
import ch.qos.logback.core.joran.action.NOPAction;
+import ch.qos.logback.core.joran.conditional.ElseAction;
+import ch.qos.logback.core.joran.conditional.IfAction;
+import ch.qos.logback.core.joran.conditional.ThenAction;
import ch.qos.logback.core.joran.spi.DefaultNestedComponentRegistry;
import ch.qos.logback.core.joran.spi.Pattern;
import ch.qos.logback.core.joran.spi.RuleStore;
@@ -68,7 +71,14 @@ public class JoranConfigurator extends JoranConfiguratorBase {
new AppenderRefAction());
rs.addRule(new Pattern("configuration/root/appender-ref"),
new AppenderRefAction());
-
+
+ // add if-then-else support
+ rs.addRule(new Pattern("*/if"), new IfAction());
+ rs.addRule(new Pattern("*/if/then"), new ThenAction());
+ rs.addRule(new Pattern("*/if/then/*"), new NOPAction());
+ rs.addRule(new Pattern("*/if/else"), new ElseAction());
+ rs.addRule(new Pattern("*/if/else/*"), new NOPAction());
+
// add jmxConfigurator only if we have JMX available.
// If running under JDK 1.4 (retrotranslateed logback) then we
// might not have JMX.
diff --git a/logback-classic/src/test/input/joran/conditional/conditionalConsoleApp.xml b/logback-classic/src/test/input/joran/conditional/conditionalConsoleApp.xml
new file mode 100644
index 0000000..52e2e64
--- /dev/null
+++ b/logback-classic/src/test/input/joran/conditional/conditionalConsoleApp.xml
@@ -0,0 +1,29 @@
+
+<configuration>
+
+ <appender name="FILE" class="ch.qos.logback.core.FileAppender">
+ <file>${randomOutputDir}/conditional.log</file>
+ <encoder>
+ <pattern>%d %-5level %logger{35} - %msg %n</pattern>
+ </encoder>
+ </appender>
+
+ <root level="ERROR">
+ <appender-ref ref="FILE" />
+ </root>
+
+
+ <if condition='property("HOSTNAME").contains("${aHost}")'>
+ <then>
+ <appender name="CON" class="ch.qos.logback.core.ConsoleAppender">
+ <encoder>
+ <pattern>%d %-5level %logger{35} - %msg %n</pattern>
+ </encoder>
+ </appender>
+ <root>
+ <appender-ref ref="CON" />
+ </root>
+ </then>
+ </if>
+
+</configuration>
\ No newline at end of file
diff --git a/logback-classic/src/test/java/ch/qos/logback/classic/joran/JoranConfiguratorTest.java b/logback-classic/src/test/java/ch/qos/logback/classic/joran/JoranConfiguratorTest.java
index 07fa46f..6512023 100644
--- a/logback-classic/src/test/java/ch/qos/logback/classic/joran/JoranConfiguratorTest.java
+++ b/logback-classic/src/test/java/ch/qos/logback/classic/joran/JoranConfiguratorTest.java
@@ -307,8 +307,10 @@ public class JoranConfiguratorTest {
assertEquals("UTF-8", encoder.getCharset().displayName());
StatusChecker checker = new StatusChecker(loggerContext);
- assertTrue(checker.isErrorFree());
-
+ assertTrue(checker.isErrorFree());
}
+
+
+
}
diff --git a/logback-classic/src/test/java/ch/qos/logback/classic/joran/conditional/ConditionalTest.java b/logback-classic/src/test/java/ch/qos/logback/classic/joran/conditional/ConditionalTest.java
new file mode 100644
index 0000000..0c1329c
--- /dev/null
+++ b/logback-classic/src/test/java/ch/qos/logback/classic/joran/conditional/ConditionalTest.java
@@ -0,0 +1,77 @@
+/**
+ * Logback: the reliable, generic, fast and flexible logging framework.
+ * Copyright (C) 1999-2010, QOS.ch. All rights reserved.
+ *
+ * This program and the accompanying materials are dual-licensed under either
+ * the terms of the Eclipse Public License v1.0 as published by the Eclipse
+ * Foundation
+ *
+ * or (per the licensee's choosing)
+ *
+ * under the terms of the GNU Lesser General Public License version 2.1 as
+ * published by the Free Software Foundation.
+ */
+package ch.qos.logback.classic.joran.conditional;
+
+import static org.junit.Assert.assertNotNull;
+
+import java.io.IOException;
+import java.net.InetAddress;
+import java.net.UnknownHostException;
+
+import org.junit.Before;
+import org.junit.Test;
+
+import ch.qos.logback.classic.ClassicTestConstants;
+import ch.qos.logback.classic.Logger;
+import ch.qos.logback.classic.LoggerContext;
+import ch.qos.logback.classic.joran.JoranConfigurator;
+import ch.qos.logback.core.ConsoleAppender;
+import ch.qos.logback.core.FileAppender;
+import ch.qos.logback.core.joran.spi.JoranException;
+import ch.qos.logback.core.testUtil.RandomUtil;
+import ch.qos.logback.core.util.CoreTestConstants;
+import ch.qos.logback.core.util.StatusPrinter;
+
+
+public class ConditionalTest {
+
+ LoggerContext context = new LoggerContext();
+ Logger root = context.getLogger(Logger.ROOT_LOGGER_NAME);
+
+
+ int diff = RandomUtil.getPositiveInt();
+ String randomOutputDir = CoreTestConstants.OUTPUT_DIR_PREFIX + diff + "/";
+
+ @Before
+ public void setUp() throws UnknownHostException {
+ context.setName("c"+diff);
+ context.putProperty("randomOutputDir", randomOutputDir);
+ InetAddress localhost = InetAddress.getLocalHost();
+ context.putProperty("aHost", localhost.getCanonicalHostName());
+ }
+
+
+ void configure(String file) throws JoranException {
+ JoranConfigurator jc = new JoranConfigurator();
+ jc.setContext(context);
+ jc.doConfigure(file);
+ }
+
+ @Test
+ public void conditionalConsoleApp() throws JoranException, IOException,
+ InterruptedException {
+
+ String configFileAsStr = ClassicTestConstants.JORAN_INPUT_PREFIX
+ + "conditional/conditionalConsoleApp.xml";
+ configure(configFileAsStr);
+ FileAppender fileAppender = (FileAppender) root.getAppender("FILE");
+ assertNotNull(fileAppender);
+
+ ConsoleAppender consoleAppender = (ConsoleAppender) root.getAppender("CON");
+ assertNotNull(consoleAppender);
+ StatusPrinter.printIfErrorsOccured(context);
+
+
+ }
+}
diff --git a/logback-core/src/main/java/ch/qos/logback/core/joran/JoranConfiguratorBase.java b/logback-core/src/main/java/ch/qos/logback/core/joran/JoranConfiguratorBase.java
index c66e5b0..2bb626a 100644
--- a/logback-core/src/main/java/ch/qos/logback/core/joran/JoranConfiguratorBase.java
+++ b/logback-core/src/main/java/ch/qos/logback/core/joran/JoranConfiguratorBase.java
@@ -29,7 +29,6 @@ import ch.qos.logback.core.joran.action.ParamAction;
import ch.qos.logback.core.joran.action.PropertyAction;
import ch.qos.logback.core.joran.action.StatusListenerAction;
import ch.qos.logback.core.joran.action.TimestampAction;
-import ch.qos.logback.core.joran.conditional.IfAction;
import ch.qos.logback.core.joran.spi.InterpretationContext;
import ch.qos.logback.core.joran.spi.Interpreter;
import ch.qos.logback.core.joran.spi.Pattern;
@@ -67,10 +66,6 @@ abstract public class JoranConfiguratorBase extends GenericConfigurator {
rs.addRule(new Pattern("configuration/timestamp"),
new TimestampAction());
- rs.addRule(new Pattern("*/if"),
- new IfAction());
-
-
// the contextProperty pattern is deprecated. It is undocumented
// and will be dropped in future versions of logback
rs.addRule(new Pattern("configuration/contextProperty"),
diff --git a/logback-core/src/main/java/ch/qos/logback/core/joran/conditional/IfAction.java b/logback-core/src/main/java/ch/qos/logback/core/joran/conditional/IfAction.java
index 23eaf7c..513d350 100644
--- a/logback-core/src/main/java/ch/qos/logback/core/joran/conditional/IfAction.java
+++ b/logback-core/src/main/java/ch/qos/logback/core/joran/conditional/IfAction.java
@@ -23,9 +23,11 @@ public class IfAction extends Action {
throws ActionException {
ic.pushObject(this);
+
Condition condition = null;
String conditionAttribute = attributes.getValue(CONDITION_ATTR);
if (!OptionHelper.isEmpty(conditionAttribute)) {
+ conditionAttribute = OptionHelper.substVars(conditionAttribute, context);
PropertyEvalScriptBuilder pesb = new PropertyEvalScriptBuilder();
pesb.setContext(context);
try {
-----------------------------------------------------------------------
Summary of changes:
.../logback/classic/joran/JoranConfigurator.java | 12 +++-
.../joran/conditional/conditionalConsoleApp.xml | 29 ++++++++
.../classic/joran/JoranConfiguratorTest.java | 6 +-
.../classic/joran/conditional/ConditionalTest.java | 77 ++++++++++++++++++++
.../logback/core/joran/JoranConfiguratorBase.java | 5 --
.../logback/core/joran/conditional/IfAction.java | 2 +
6 files changed, 123 insertions(+), 8 deletions(-)
create mode 100644 logback-classic/src/test/input/joran/conditional/conditionalConsoleApp.xml
create mode 100644 logback-classic/src/test/java/ch/qos/logback/classic/joran/conditional/ConditionalTest.java
hooks/post-receive
--
Logback: the generic, reliable, fast and flexible logging framework.
More information about the logback-dev
mailing list