[logback-dev] svn commit: r2038 - in logback/trunk/logback-classic/src: main/java/ch/qos/logback/classic/joran/action test/input/joran test/java/ch/qos/logback/classic/joran
noreply.ceki at qos.ch
noreply.ceki at qos.ch
Fri Nov 28 23:29:14 CET 2008
Author: ceki
Date: Fri Nov 28 23:29:14 2008
New Revision: 2038
Added:
logback/trunk/logback-classic/src/test/input/joran/loggerLevelByProperty.xml
logback/trunk/logback-classic/src/test/input/joran/rootLevelByProperty.xml
Modified:
logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/joran/action/LevelAction.java
logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/joran/action/LoggerAction.java
logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/joran/action/RootLoggerAction.java
logback/trunk/logback-classic/src/test/input/joran/evaluatorFilter.xml
logback/trunk/logback-classic/src/test/input/joran/ignore.xml
logback/trunk/logback-classic/src/test/input/joran/levelFilter.xml
logback/trunk/logback-classic/src/test/input/joran/simpleLevel.xml
logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/joran/JoranConfiguratorTest.java
Log:
- Added support variable substitution for the level attribute in <logger> and <root> elements
- relevant test cases
Modified: logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/joran/action/LevelAction.java
==============================================================================
--- logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/joran/action/LevelAction.java (original)
+++ logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/joran/action/LevelAction.java Fri Nov 28 23:29:14 2008
@@ -42,7 +42,7 @@
String loggerName = l.getName();
- String levelStr = attributes.getValue(ActionConst.VALUE_ATTR);
+ String levelStr = ec.subst(attributes.getValue(ActionConst.VALUE_ATTR));
//addInfo("Encapsulating logger name is [" + loggerName
// + "], level value is [" + levelStr + "].");
Modified: logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/joran/action/LoggerAction.java
==============================================================================
--- logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/joran/action/LoggerAction.java (original)
+++ logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/joran/action/LoggerAction.java Fri Nov 28 23:29:14 2008
@@ -50,7 +50,8 @@
logger = loggerContext.getLogger(loggerName);
- String levelStr = attributes.getValue(LEVEL_ATTRIBUTE);
+ String levelStr = ec.subst(attributes.getValue(LEVEL_ATTRIBUTE));
+
if (!OptionHelper.isEmpty(levelStr)) {
if (ActionConst.INHERITED.equalsIgnoreCase(levelStr)
|| ActionConst.NULL.equalsIgnoreCase(levelStr)) {
Modified: logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/joran/action/RootLoggerAction.java
==============================================================================
--- logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/joran/action/RootLoggerAction.java (original)
+++ logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/joran/action/RootLoggerAction.java Fri Nov 28 23:29:14 2008
@@ -1,7 +1,7 @@
/**
- * LOGBack: the generic, reliable, fast and flexible logging framework.
+ * Logback: the generic, reliable, fast and flexible logging framework.
*
- * Copyright (C) 1999-2006, QOS.ch
+ * Copyright (C) 2000-2008, 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
@@ -30,7 +30,7 @@
LoggerContext loggerContext = (LoggerContext) this.context;
root = loggerContext.getLogger(LoggerContext.ROOT_NAME);
- String levelStr = attributes.getValue(ActionConst.LEVEL_ATTRIBUTE);
+ String levelStr = ec.subst(attributes.getValue(ActionConst.LEVEL_ATTRIBUTE));
if (!OptionHelper.isEmpty(levelStr)) {
Level level = Level.toLevel(levelStr);
addInfo("Setting level of ROOT logger to " + level);
Modified: logback/trunk/logback-classic/src/test/input/joran/evaluatorFilter.xml
==============================================================================
--- logback/trunk/logback-classic/src/test/input/joran/evaluatorFilter.xml (original)
+++ logback/trunk/logback-classic/src/test/input/joran/evaluatorFilter.xml Fri Nov 28 23:29:14 2008
@@ -13,8 +13,7 @@
</filter>
</appender>
- <root>
- <level value="debug" />
+ <root level="debug">
<appender-ref ref="LIST" />
</root>
</configuration>
\ No newline at end of file
Modified: logback/trunk/logback-classic/src/test/input/joran/ignore.xml
==============================================================================
--- logback/trunk/logback-classic/src/test/input/joran/ignore.xml (original)
+++ logback/trunk/logback-classic/src/test/input/joran/ignore.xml Fri Nov 28 23:29:14 2008
@@ -12,8 +12,7 @@
</layout>
</appender>
- <root>
- <level value="DEBUG" />
+ <root level="DEBUG">
<appender-ref ref="CONSOLE" />
</root>
Modified: logback/trunk/logback-classic/src/test/input/joran/levelFilter.xml
==============================================================================
--- logback/trunk/logback-classic/src/test/input/joran/levelFilter.xml (original)
+++ logback/trunk/logback-classic/src/test/input/joran/levelFilter.xml Fri Nov 28 23:29:14 2008
@@ -1,7 +1,6 @@
<configuration>
- <appender name="LIST"
- class="ch.qos.logback.core.read.ListAppender">
+ <appender name="LIST" class="ch.qos.logback.core.read.ListAppender">
<filter class="ch.qos.logback.classic.filter.LevelFilter">
<OnMatch>DENY</OnMatch>
@@ -9,8 +8,7 @@
</filter>
</appender>
- <root>
- <level value="debug" />
+ <root level="debug">
<appender-ref ref="LIST" />
</root>
</configuration>
\ No newline at end of file
Added: logback/trunk/logback-classic/src/test/input/joran/loggerLevelByProperty.xml
==============================================================================
--- (empty file)
+++ logback/trunk/logback-classic/src/test/input/joran/loggerLevelByProperty.xml Fri Nov 28 23:29:14 2008
@@ -0,0 +1,14 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<!DOCTYPE configuration>
+
+<configuration debug="false">
+
+ <appender name="LIST" class="ch.qos.logback.core.read.ListAppender" />
+
+ <logger name="ch.qos.logback.classic.joran" level="${logback.level}" />
+
+ <root level="ERROR">
+ <appender-ref ref="LIST" />
+ </root>
+
+</configuration>
Added: logback/trunk/logback-classic/src/test/input/joran/rootLevelByProperty.xml
==============================================================================
--- (empty file)
+++ logback/trunk/logback-classic/src/test/input/joran/rootLevelByProperty.xml Fri Nov 28 23:29:14 2008
@@ -0,0 +1,13 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<!DOCTYPE configuration>
+
+<configuration debug="false">
+
+ <appender name="LIST" class="ch.qos.logback.core.read.ListAppender" />
+
+ <root level="${logback.level}">
+
+ <appender-ref ref="LIST" />
+ </root>
+
+</configuration>
Modified: logback/trunk/logback-classic/src/test/input/joran/simpleLevel.xml
==============================================================================
--- logback/trunk/logback-classic/src/test/input/joran/simpleLevel.xml (original)
+++ logback/trunk/logback-classic/src/test/input/joran/simpleLevel.xml Fri Nov 28 23:29:14 2008
@@ -3,17 +3,12 @@
<configuration debug="false">
- <appender name="LIST" class="ch.qos.logback.core.read.ListAppender"/>
-
-
- <logger name="ch.qos.logback.classic.joran">
- <level value="INFO" />
- </logger>
+ <appender name="LIST" class="ch.qos.logback.core.read.ListAppender" />
- <root>
- <level value="DEBUG" />
+ <logger name="ch.qos.logback.classic.joran" level="INFO" />
+
+ <root level="DEBUG">
<appender-ref ref="LIST" />
</root>
-
+
</configuration>
-
\ No newline at end of file
Modified: logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/joran/JoranConfiguratorTest.java
==============================================================================
--- logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/joran/JoranConfiguratorTest.java (original)
+++ logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/joran/JoranConfiguratorTest.java Fri Nov 28 23:29:14 2008
@@ -67,6 +67,36 @@
}
@Test
+ public void testRootLoggerLevelSettingBySystemProperty() throws JoranException {
+ String propertyName = "logback.level";
+
+ System.setProperty(propertyName, "INFO");
+ configure(TeztConstants.TEST_DIR_PREFIX + "input/joran/rootLevelByProperty.xml");
+ StatusPrinter.print(loggerContext);
+ ListAppender listAppender = (ListAppender) root.getAppender("LIST");
+ assertEquals(0, listAppender.list.size());
+ String msg = "hello world";
+ logger.debug(msg);
+ assertEquals(0, listAppender.list.size());
+ System.clearProperty(propertyName);
+ }
+
+ @Test
+ public void testLoggerLevelSettingBySystemProperty() throws JoranException {
+ String propertyName = "logback.level";
+
+ System.setProperty(propertyName, "DEBUG");
+ configure(TeztConstants.TEST_DIR_PREFIX + "input/joran/loggerLevelByProperty.xml");
+ StatusPrinter.print(loggerContext);
+ ListAppender listAppender = (ListAppender) root.getAppender("LIST");
+ assertEquals(0, listAppender.list.size());
+ String msg = "hello world";
+ logger.debug(msg);
+ assertEquals(1, listAppender.list.size());
+ System.clearProperty(propertyName);
+ }
+
+ @Test
public void testStatusListener() throws JoranException {
configure(TeztConstants.TEST_DIR_PREFIX + "input/joran/statusListener.xml");
More information about the logback-dev
mailing list