r500169 | eross | 2007-01-26 01:39:25 -0600 (Fri, 26 Jan 2007) | 1 line

Bug 17531 - Add "reset" option to <configuration> element


Index: src/java/org/apache/log4j/joran/action/ConfigurationAction.java
===================================================================
29a30
>   static final String RESET_ATTR = "reset";
31a33,41
>   private boolean trueBoolean(String name, String debugAttrib) {
>     if (debugAttrib == null || debugAttrib.equals("")
> || debugAttrib.equals("false") || debugAttrib.equals ("null")) {
>       getLogger().debug("Ignoring " + name + " attribute.");
>       return false;
>     }
>     return true;
>   }
>
33d42
<     String debugAttrib = attributes.getValue(INTERNAL_DEBUG_ATTR);
35,39c44,53
<     if (
<       (debugAttrib == null) || debugAttrib.equals("")
< || debugAttrib.equals("false") || debugAttrib.equals ("null")) { < getLogger().debug("Ignoring " + INTERNAL_DEBUG_ATTR + " attribute.");
<     } else {
---
>     // reset is applied before debug
>     String resetAttrib = attributes.getValue(RESET_ATTR);
>     boolean reset = trueBoolean(RESET_ATTR, resetAttrib);
>     if (reset) {
> LoggerRepository repository = (LoggerRepository) ec.getObject (0);
>       repository.resetConfiguration();
>     }
>
>     String debugAttrib = attributes.getValue(INTERNAL_DEBUG_ATTR);
>     if (trueBoolean(INTERNAL_DEBUG_ATTR, debugAttrib)) {
44a59,63
>
>     if (reset) {
>       getLogger().debug("Reset configuration");
>     }
>
Index: src/java/org/apache/log4j/xml/log4j.dtd
===================================================================
29a30,33
> <!-- Setting "reset" to "true" resets the logger repository when the --> > <!-- configuration is used. By default (for compatibility) this --> > <!-- setting is "false". -->
>
33a38
>   reset                    (true|false)       "false"
Index: tests/input/xml/resetTest.xml
===================================================================
0a1,18
> <?xml version="1.0" encoding="UTF-8" ?>
> <!DOCTYPE log4j:configuration>
>
> <log4j:configuration xmlns:log4j='http://logging.apache.org/' debug='true' reset='true'>
>
>   <appender name="CONSOLE" class="org.apache.log4j.ConsoleAppender">
>     <layout class="org.apache.log4j.PatternLayout">
>       <param name="ConversionPattern" value="%m%n"/>
>     </layout>        
>   </appender>
>
>   <logger name="foo"><level value="INFO" /></logger>
>
>   <root>
>     <appender-ref ref="CONSOLE" />
>   </root>
>
> </log4j:configuration>
\ No newline at end of file
Index: tests/src/java/org/apache/log4j/xml/ResetTest.java
===================================================================
0a1,33
> package org.apache.log4j.xml;
>
> import org.apache.log4j.Level;
> import org.apache.log4j.LogManager;
> import org.apache.log4j.Logger;
> import org.apache.log4j.joran.JoranConfigurator;
>
> import junit.framework.TestCase;
>
> public class ResetTest extends TestCase {
>
>   public void testNoReset() {
>     test("input/xml/resetTest.xml", true);
>     test("input/xml/defaultInit.xml", false);
>   }
>
>   private void test(String file, boolean reset)
>   {
>     LogManager.getLoggerRepository().resetConfiguration();
>     Logger l = Logger.getLogger("x");
>     l.setLevel(Level.ERROR);
>     assertEquals(Level.ERROR, l.getLevel());
>
>     JoranConfigurator jc = new JoranConfigurator();
>     jc.doConfigure(file, LogManager.getLoggerRepository());
>     if (reset)
>       assertEquals(null, l.getLevel());
>     else
>       assertEquals(Level.ERROR, l.getLevel());
>   }
>
>
> }


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to