logging-log4j-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From c...@apache.org
Subject cvs commit: jakarta-log4j/tests/src/java/org/apache/joran JoranParserTest.java
Date Thu, 25 Sep 2003 09:28:18 GMT
ceki        2003/09/25 02:28:18

  Modified:    src/java/org/apache/joran/action ParamAction.java
                        NestComponentIA.java NewRuleAction.java Action.java
               tests/src/java/org/apache/joran JoranParserTest.java
  Added:       src/java/org/apache/log4j/joran/action LevelAction.java
                        ActionConst.java ConversionRuleAction.java
                        LoggerAction.java AppenderRefAction.java
                        AppenderAction.java RootLoggerAction.java
                        LayoutAction.java
  Removed:     src/java/org/apache/joran/action ConversionRuleAction.java
                        AppenderAction.java LevelAction.java
                        AppenderRefAction.java RootLoggerAction.java
                        LoggerAction.java ActionConst.java
                        LayoutAction.java
               docs     SUMMARY
  Log:
  
  - Rearranged log4j specific Actions.
  
  Revision  Changes    Path
  1.3       +2 -2      jakarta-log4j/src/java/org/apache/joran/action/ParamAction.java
  
  Index: ParamAction.java
  ===================================================================
  RCS file: /home/cvs/jakarta-log4j/src/java/org/apache/joran/action/ParamAction.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- ParamAction.java	11 Sep 2003 17:00:42 -0000	1.2
  +++ ParamAction.java	25 Sep 2003 09:28:17 -0000	1.3
  @@ -16,8 +16,8 @@
   	static String NO_VALUE = "No name attribute in <param> element";
   	
     public void begin(ExecutionContext ec, Element element) {
  -		String name = element.getAttribute(ActionConst.NAME_ATTRIBUTE);
  -		String value = (element.getAttribute(ActionConst.VALUE_ATTRIBUTE));
  +		String name = element.getAttribute(NAME_ATTRIBUTE);
  +		String value = (element.getAttribute(VALUE_ATTRIBUTE));
   
       if(name==null) {
   			inError = true;
  
  
  
  1.2       +3 -2      jakarta-log4j/src/java/org/apache/joran/action/NestComponentIA.java
  
  Index: NestComponentIA.java
  ===================================================================
  RCS file: /home/cvs/jakarta-log4j/src/java/org/apache/joran/action/NestComponentIA.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- NestComponentIA.java	12 Sep 2003 18:24:26 -0000	1.1
  +++ NestComponentIA.java	25 Sep 2003 09:28:17 -0000	1.2
  @@ -50,6 +50,7 @@
   package org.apache.joran.action;
   
   import org.apache.joran.ExecutionContext;
  +import org.apache.joran.helper.Option;
   
   import org.apache.log4j.Logger;
   import org.apache.log4j.config.PropertySetter;
  @@ -99,10 +100,10 @@
     public void begin(ExecutionContext ec, Element e) {
       // inError was reset in isApplicable. It should not be touched here
   
  -      String className = e.getAttribute(ActionConst.CLASS_ATTRIBUTE);
  +      String className = e.getAttribute(CLASS_ATTRIBUTE);
         
         String tagName = e.getTagName();
  -      if(className == null || ActionConst.EMPTY_STR.equals(className)) {
  +      if(Option.isEmpty(className)) {
           inError = true;
           String errMsg = "No class name attribute in <"+tagName+">";
           logger.error(errMsg);
  
  
  
  1.2       +3 -4      jakarta-log4j/src/java/org/apache/joran/action/NewRuleAction.java
  
  Index: NewRuleAction.java
  ===================================================================
  RCS file: /home/cvs/jakarta-log4j/src/java/org/apache/joran/action/NewRuleAction.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- NewRuleAction.java	23 Sep 2003 18:52:50 -0000	1.1
  +++ NewRuleAction.java	25 Sep 2003 09:28:17 -0000	1.2
  @@ -55,7 +55,6 @@
   
   import org.apache.log4j.Layout;
   import org.apache.log4j.Logger;
  -import org.apache.log4j.PatternLayout;
   
   import org.w3c.dom.Element;
   
  @@ -72,12 +71,12 @@
   		// Let us forget about previous errors (in this object)
   		inError = false; 
       String errorMsg;
  -    String pattern =  element.getAttribute(ActionConst.PATTERN_ATTRIBUTE);
  -    String actionClass =  element.getAttribute(ActionConst.ACTION_CLASS_ATTRIBUTE);
  +    String pattern =  element.getAttribute(PATTERN_ATTRIBUTE);
  +    String actionClass =  element.getAttribute(ACTION_CLASS_ATTRIBUTE);
   
       if(Option.isEmpty(pattern)) {
          inError = true;
  -       errorMsg = "No 'patern' attribute in <newRule>";
  +       errorMsg = "No 'pattern' attribute in <newRule>";
          logger.warn(errorMsg);
          ec.addError(errorMsg);
          return;
  
  
  
  1.4       +7 -0      jakarta-log4j/src/java/org/apache/joran/action/Action.java
  
  Index: Action.java
  ===================================================================
  RCS file: /home/cvs/jakarta-log4j/src/java/org/apache/joran/action/Action.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- Action.java	11 Sep 2003 17:00:42 -0000	1.3
  +++ Action.java	25 Sep 2003 09:28:17 -0000	1.4
  @@ -69,6 +69,13 @@
    */
   public abstract class Action {
   	
  +  public static final String NAME_ATTRIBUTE = "name";
  +  public static final String VALUE_ATTRIBUTE = "value";
  +  public static final String CLASS_ATTRIBUTE = "class";
  +  public static final String PATTERN_ATTRIBUTE = "pattern";
  +  public static final String ACTION_CLASS_ATTRIBUTE = "actionClass";
  +
  +  
   	/** 
   	 * When actions encounter an error condition they set this variable to true. 
   	 */
  
  
  
  1.1                  jakarta-log4j/src/java/org/apache/log4j/joran/action/LevelAction.java
  
  Index: LevelAction.java
  ===================================================================
  package org.apache.log4j.joran.action;
  
  import org.apache.joran.ExecutionContext;
  import org.apache.joran.action.Action;
  
  import org.apache.log4j.Level;
  import org.apache.log4j.Logger;
  import org.apache.log4j.helpers.Loader;
  import org.apache.log4j.helpers.OptionConverter;
  import org.w3c.dom.Element;
  
  import java.lang.reflect.Method;
  
  public class LevelAction extends Action {
  
    final static Logger logger = Logger.getLogger(LevelAction.class);
  
    static final String VALUE_ATTR = "value";
  	static final String CLASS_ATTR = "class";
    static final String INHERITED = "INHERITED";
    static final String NULL = "NULL";
    static final String EMPTY_STR = "";
  
    static final Class[] ONE_STRING_PARAM = new Class[] { String.class };
  
    public void begin(ExecutionContext ec, Element element) {
      
  		Object o = ec.peekObject();
  		
  		if(!(o instanceof Logger)) {
  			logger.warn("Could not find a logger at the top of execution stack.");
  			inError = true; 
  			ec.addError("For element <level>, could not find a logger at the top of execution
stack.");
  			return;
  		}
      Logger l = (Logger) o;
      
      
      String loggerName = l.getName();
  
      String levelStr = element.getAttribute(VALUE_ATTR);
      logger.debug(
        "Level value for logger [" + loggerName + "] is  [" + levelStr + "].");
  
      if (INHERITED.equalsIgnoreCase(levelStr)
        || NULL.equalsIgnoreCase(levelStr)) {
        l.setLevel(null);
      } else {
  
        String className = element.getAttribute(CLASS_ATTR);
  
        if (EMPTY_STR.equals(className)) {
          l.setLevel(OptionConverter.toLevel(levelStr, Level.DEBUG));
        } else {
          logger.debug("Desired Level sub-class: [" + className + ']');
  
          try {
            Class clazz = Loader.loadClass(className);
            Method toLevelMethod = clazz.getMethod("toLevel", ONE_STRING_PARAM);
            Level pri =
              (Level) toLevelMethod.invoke(null, new Object[] { levelStr });
            l.setLevel(pri);
          } catch (Exception oops) {
            logger.error(
              "Could not create level [" + levelStr + "]. Reported error follows.",
              oops);
            return;
          }
        }
      }
  
      logger.debug(loggerName + " level set to " + l.getLevel());
  
    }
  
    public void end(ExecutionContext ec, Element e) {
    }
  
    public void finish(ExecutionContext ec) {
    }
  }
  
  
  
  1.1                  jakarta-log4j/src/java/org/apache/log4j/joran/action/ActionConst.java
  
  Index: ActionConst.java
  ===================================================================
  
  package org.apache.log4j.joran.action;
  
  /**
   *
   * This class contains costants used by other Actions.
   * 
   * @author Ceki G&uuml;lc&uuml;
   *
   */
  public abstract class ActionConst {
  	
  	public static final String APPENDER_TAG = "appender";
  	public static final String REF_ATTRIBUTE = "ref";
    public static final String ADDITIVITY_ATTRIBUTE = "additivity";
    public static final String CONVERTER_CLASS_ATTRIBUTE = "converterClass";
    public static final String CONVERSION_WORD_ATTRIBUTE = "conversionWord";
    public static final String PATTERN_ATTRIBUTE = "pattern";
  public static final String
ACTION_CLASS_ATTRIBUTE = "actionClass";
  
  	static final String INHERITED = "INHERITED";
  	static final String NULL = "NULL";
  	static final Class[] ONE_STRING_PARAM = new Class[] { String.class };
  
  	public static final String APPENDER_BAG = "APPENDER_BAG";
  	
  
  }
  
  
  
  1.1                  jakarta-log4j/src/java/org/apache/log4j/joran/action/ConversionRuleAction.java
  
  Index: ConversionRuleAction.java
  ===================================================================
  /*
   * ============================================================================
   *                   The Apache Software License, Version 1.1
   * ============================================================================
   *
   *    Copyright (C) 1999 The Apache Software Foundation. All rights reserved.
   *
   * Redistribution and use in source and binary forms, with or without modifica-
   * tion, are permitted provided that the following conditions are met:
   *
   * 1. Redistributions of  source code must  retain the above copyright  notice,
   *    this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright notice,
   *    this list of conditions and the following disclaimer in the documentation
   *    and/or other materials provided with the distribution.
   *
   * 3. The end-user documentation included with the redistribution, if any, must
   *    include  the following  acknowledgment:  "This product includes  software
   *    developed  by the  Apache Software Foundation  (http://www.apache.org/)."
   *    Alternately, this  acknowledgment may  appear in the software itself,  if
   *    and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "log4j" and  "Apache Software Foundation"  must not be used to
   *    endorse  or promote  products derived  from this  software without  prior
   *    written permission. For written permission, please contact
   *    apache@apache.org.
   *
   * 5. Products  derived from this software may not  be called "Apache", nor may
   *    "Apache" appear  in their name,  without prior written permission  of the
   *    Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
   * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
   * FITNESS  FOR A PARTICULAR  PURPOSE ARE  DISCLAIMED.  IN NO  EVENT SHALL  THE
   * APACHE SOFTWARE  FOUNDATION  OR ITS CONTRIBUTORS  BE LIABLE FOR  ANY DIRECT,
   * INDIRECT, INCIDENTAL, SPECIAL,  EXEMPLARY, OR CONSEQUENTIAL  DAMAGES (INCLU-
   * DING, BUT NOT LIMITED TO, PROCUREMENT  OF SUBSTITUTE GOODS OR SERVICES; LOSS
   * OF USE, DATA, OR  PROFITS; OR BUSINESS  INTERRUPTION)  HOWEVER CAUSED AND ON
   * ANY  THEORY OF LIABILITY,  WHETHER  IN CONTRACT,  STRICT LIABILITY,  OR TORT
   * (INCLUDING  NEGLIGENCE OR  OTHERWISE) ARISING IN  ANY WAY OUT OF THE  USE OF
   * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
   *
   * This software  consists of voluntary contributions made  by many individuals
   * on  behalf of the Apache Software  Foundation.  For more  information on the
   * Apache Software Foundation, please see <http://www.apache.org/>.
   *
   */
  
  package org.apache.log4j.joran.action;
  
  import org.apache.joran.ExecutionContext;
  import org.apache.joran.action.Action;
  import org.apache.joran.helper.Option;
  
  import org.apache.log4j.Layout;
  import org.apache.log4j.Logger;
  import org.apache.log4j.PatternLayout;
  
  import org.w3c.dom.Element;
  
  
  public class ConversionRuleAction extends Action {
    static final Logger logger = Logger.getLogger(ConversionRuleAction.class);
    Layout layout;
  
    /**
     * Instantiates an layout of the given class and sets its name.
     *
     */
    public void begin(ExecutionContext ec, Element element) {
      // Let us forget about previous errors (in this object)
      inError = false;
  
      String errorMsg;
      String conversionWord =
        element.getAttribute(ActionConst.CONVERSION_WORD_ATTRIBUTE);
      String converterClass =
        element.getAttribute(ActionConst.CONVERTER_CLASS_ATTRIBUTE);
  
      if (Option.isEmpty(conversionWord)) {
        inError = true;
        errorMsg = "No 'conversionWord' attribute in <conversionRule>";
        logger.warn(errorMsg);
        ec.addError(errorMsg);
  
        return;
      }
  
      if (Option.isEmpty(converterClass)) {
        inError = true;
        errorMsg = "No 'converterClass' attribute in <conversionRule>";
        logger.warn(errorMsg);
        ec.addError(errorMsg);
  
        return;
      }
  
      try {
        logger.debug(
          "About to add conversion rule [" + conversionWord + ", "
          + converterClass + "] to layout");
  
        Object o = ec.peekObject();
  
        if (o instanceof PatternLayout) {
          PatternLayout patternLayout = (PatternLayout) o;
          patternLayout.addConversionRule(conversionWord, converterClass);
        }
      } catch (Exception oops) {
        inError = true;
        errorMsg = "Could not add conversion rule to PatternLayout.";
        logger.error(errorMsg, oops);
        ec.addError(errorMsg);
      }
    }
  
    /**
     * Once the children elements are also parsed, now is the time to activate
     * the appender options.
     */
    public void end(ExecutionContext ec, Element e) {
    }
  
    public void finish(ExecutionContext ec) {
    }
  }
  
  
  
  1.1                  jakarta-log4j/src/java/org/apache/log4j/joran/action/LoggerAction.java
  
  Index: LoggerAction.java
  ===================================================================
  package org.apache.log4j.joran.action;
  
  import org.apache.joran.ExecutionContext;
  import org.apache.joran.action.Action;
  import org.apache.joran.helper.Option;
  
  import org.apache.log4j.Logger;
  import org.apache.log4j.helpers.Loader;
  import org.apache.log4j.helpers.OptionConverter;
  import org.apache.log4j.spi.LoggerRepository;
  
  import org.w3c.dom.Element;
  
  import java.lang.reflect.Method;
  
  public class LoggerAction extends Action {
  	
    Logger logger = Logger.getLogger(LoggerAction.class);
  
    public void begin(ExecutionContext ec, Element loggerElement) {
    	// Let us forget about previous errors (in this object)
    	inError = false; 
    	
      LoggerRepository repository = (LoggerRepository) ec.getObject(0);
  
      // Create a new org.apache.log4j.Category object from the <category> element.
      String loggerName = loggerElement.getAttribute(NAME_ATTRIBUTE);
      if(Option.isEmpty(loggerName)) {
        inError = true;
  			String errorMsg = "No 'name' attribute in element "
  				+loggerElement.getTagName();
  			logger.warn(errorMsg);
        ec.addError(errorMsg);
        return;
      }
      
  		logger.debug("Logger name is ["+loggerName+"].");
  
      Logger l;
  
      String className = loggerElement.getAttribute(CLASS_ATTRIBUTE);
  
      if (Option.isEmpty(className)) {
        logger.debug("Retreiving an instance of org.apache.log4j.Logger.");
        l = repository.getLogger(loggerName);
      } else {
        logger.debug("Desired logger sub-class: [" + className + ']');
  
        try {
          Class clazz = Loader.loadClass(className);
          Method getInstanceMethod =
            clazz.getMethod("getLogger", ActionConst.ONE_STRING_PARAM);
          l = (Logger) getInstanceMethod.invoke(null, new Object[] { loggerName });
        } catch (Exception oops) {
          logger.error(
            "Could not retrieve category ["
              + loggerName
              + "]. Reported error follows.",
            oops);
          return;
        }     
      }
  
      boolean additivity =
        OptionConverter.toBoolean(
          loggerElement.getAttribute(ActionConst.ADDITIVITY_ATTRIBUTE),
          true);
      logger.debug(
        "Setting [" + l.getName() + "] additivity to [" + additivity + "].");
      l.setAdditivity(additivity);
      
      logger.debug("Pushing logger named ["+loggerName+"].");
  		ec.pushObject(l);
    }
  
    public void end(ExecutionContext ec, Element e) {
    	logger.debug("end() called.");
    	if(!inError) {
  			logger.debug("Removing logger from stack.");
    	  ec.popObject();
    	}
    }
  
    public void finish(ExecutionContext ec) {
    }
    
  }
  
  
  
  1.1                  jakarta-log4j/src/java/org/apache/log4j/joran/action/AppenderRefAction.java
  
  Index: AppenderRefAction.java
  ===================================================================
  /*
   * ============================================================================
   *                   The Apache Software License, Version 1.1
   * ============================================================================
   *
   *    Copyright (C) 1999 The Apache Software Foundation. All rights reserved.
   *
   * Redistribution and use in source and binary forms, with or without modifica-
   * tion, are permitted provided that the following conditions are met:
   *
   * 1. Redistributions of  source code must  retain the above copyright  notice,
   *    this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright notice,
   *    this list of conditions and the following disclaimer in the documentation
   *    and/or other materials provided with the distribution.
   *
   * 3. The end-user documentation included with the redistribution, if any, must
   *    include  the following  acknowledgment:  "This product includes  software
   *    developed  by the  Apache Software Foundation  (http://www.apache.org/)."
   *    Alternately, this  acknowledgment may  appear in the software itself,  if
   *    and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "log4j" and  "Apache Software Foundation"  must not be used to
   *    endorse  or promote  products derived  from this  software without  prior
   *    written permission. For written permission, please contact
   *    apache@apache.org.
   *
   * 5. Products  derived from this software may not  be called "Apache", nor may
   *    "Apache" appear  in their name,  without prior written permission  of the
   *    Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
   * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
   * FITNESS  FOR A PARTICULAR  PURPOSE ARE  DISCLAIMED.  IN NO  EVENT SHALL  THE
   * APACHE SOFTWARE  FOUNDATION  OR ITS CONTRIBUTORS  BE LIABLE FOR  ANY DIRECT,
   * INDIRECT, INCIDENTAL, SPECIAL,  EXEMPLARY, OR CONSEQUENTIAL  DAMAGES (INCLU-
   * DING, BUT NOT LIMITED TO, PROCUREMENT  OF SUBSTITUTE GOODS OR SERVICES; LOSS
   * OF USE, DATA, OR  PROFITS; OR BUSINESS  INTERRUPTION)  HOWEVER CAUSED AND ON
   * ANY  THEORY OF LIABILITY,  WHETHER  IN CONTRACT,  STRICT LIABILITY,  OR TORT
   * (INCLUDING  NEGLIGENCE OR  OTHERWISE) ARISING IN  ANY WAY OUT OF THE  USE OF
   * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
   *
   * This software  consists of voluntary contributions made  by many individuals
   * on  behalf of the Apache Software  Foundation.  For more  information on the
   * Apache Software Foundation, please see <http://www.apache.org/>.
   *
   */
  
  package org.apache.log4j.joran.action;
  
  import org.apache.joran.ExecutionContext;
  import org.apache.joran.action.Action;
  import org.apache.joran.helper.Option;
  import org.apache.log4j.Appender;
  import org.apache.log4j.Logger;
  import org.apache.log4j.spi.AppenderAttachable;
  
  import org.w3c.dom.Element;
  import org.w3c.dom.Node;
  import java.util.HashMap;
  
  
  public class AppenderRefAction extends Action {
    static final Logger logger = Logger.getLogger(AppenderRefAction.class);
  
    public void begin(ExecutionContext ec, Element appenderRef) {
  		// Let us forget about previous errors (in this object)
  		inError = false; 
  
      logger.debug("begin called");
  
      Object o = ec.peekObject();
  
      if (!(o instanceof AppenderAttachable)) {
        logger.warn(
          "Could not find an AppenderAttachable object at the top of execution stack.");
        inError = true;
        ec.addError(
          "For element <appender-ref>, could not find a  AppenderAttachable object at
the top of execution stack.");
  
        return;
      }
  
      AppenderAttachable appenderAttachable = (AppenderAttachable) o;
  
      String appenderName = appenderRef.getAttribute(ActionConst.REF_ATTRIBUTE);
  
      if (Option.isEmpty(appenderName)) {
        // print a meaningful error message and return
        Node parentNode = appenderRef.getParentNode();
        String errMsg = "Missing appender ref attribute in <appender-ref> tag.";
  
        if (parentNode instanceof Element) {
          Element parentElement = (Element) parentNode;
          String parentTag = parentElement.getTagName();
  
          if ("logger".equals(parentTag)) {
            String loggerName = parentElement.getAttribute("name");
            errMsg =
              errMsg + " Within <" + parentTag + ">" + " named [" + loggerName
              + "].";
          }
  
          errMsg = errMsg + " Within <" + parentTag + ">";
        }
  
        parentNode.getAttributes();
        logger.warn(errMsg);
        inError = true;
        ec.addError(errMsg);
  
        return;
      }
  
      HashMap appenderBag =
        (HashMap) ec.getObjectMap().get(ActionConst.APPENDER_BAG);
      Appender appender = (Appender) appenderBag.get(appenderName);
  
      if (appender == null) {
        logger.warn("Could not find an appender named [" + appenderName + "]");
        inError = true;
        ec.addError("Could not find an appender named [" + appenderName + "]");
  
        return;
      }
  
  
      if(appenderAttachable instanceof Logger) {
      logger.debug(
        "Attaching appender named [" + appenderName + "] to logger named ["
        + ((Logger)appenderAttachable).getName() +"].");
      } else {
  			logger.debug(
  					 "Attaching appender named [" + appenderName + "] to "
  					 + appenderAttachable);
      }
      appenderAttachable.addAppender(appender);
    }
  
    public void end(ExecutionContext ec, Element e) {
    }
  
    public void finish(ExecutionContext ec) {
    }
  }
  
  
  
  1.1                  jakarta-log4j/src/java/org/apache/log4j/joran/action/AppenderAction.java
  
  Index: AppenderAction.java
  ===================================================================
  /*
   * ============================================================================
   *                   The Apache Software License, Version 1.1
   * ============================================================================
   *
   *    Copyright (C) 1999 The Apache Software Foundation. All rights reserved.
   *
   * Redistribution and use in source and binary forms, with or without modifica-
   * tion, are permitted provided that the following conditions are met:
   *
   * 1. Redistributions of  source code must  retain the above copyright  notice,
   *    this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright notice,
   *    this list of conditions and the following disclaimer in the documentation
   *    and/or other materials provided with the distribution.
   *
   * 3. The end-user documentation included with the redistribution, if any, must
   *    include  the following  acknowledgment:  "This product includes  software
   *    developed  by the  Apache Software Foundation  (http://www.apache.org/)."
   *    Alternately, this  acknowledgment may  appear in the software itself,  if
   *    and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "log4j" and  "Apache Software Foundation"  must not be used to
   *    endorse  or promote  products derived  from this  software without  prior
   *    written permission. For written permission, please contact
   *    apache@apache.org.
   *
   * 5. Products  derived from this software may not  be called "Apache", nor may
   *    "Apache" appear  in their name,  without prior written permission  of the
   *    Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
   * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
   * FITNESS  FOR A PARTICULAR  PURPOSE ARE  DISCLAIMED.  IN NO  EVENT SHALL  THE
   * APACHE SOFTWARE  FOUNDATION  OR ITS CONTRIBUTORS  BE LIABLE FOR  ANY DIRECT,
   * INDIRECT, INCIDENTAL, SPECIAL,  EXEMPLARY, OR CONSEQUENTIAL  DAMAGES (INCLU-
   * DING, BUT NOT LIMITED TO, PROCUREMENT  OF SUBSTITUTE GOODS OR SERVICES; LOSS
   * OF USE, DATA, OR  PROFITS; OR BUSINESS  INTERRUPTION)  HOWEVER CAUSED AND ON
   * ANY  THEORY OF LIABILITY,  WHETHER  IN CONTRACT,  STRICT LIABILITY,  OR TORT
   * (INCLUDING  NEGLIGENCE OR  OTHERWISE) ARISING IN  ANY WAY OUT OF THE  USE OF
   * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
   *
   * This software  consists of voluntary contributions made  by many individuals
   * on  behalf of the Apache Software  Foundation.  For more  information on the
   * Apache Software Foundation, please see <http://www.apache.org/>.
   *
   */
  
  package org.apache.log4j.joran.action;
  
  import org.apache.joran.ExecutionContext;
  import org.apache.joran.action.Action;
  import org.apache.joran.helper.Option;
  
  import org.apache.log4j.Appender;
  import org.apache.log4j.Logger;
  import org.apache.log4j.helpers.OptionConverter;
  import org.apache.log4j.spi.OptionHandler;
  
  import org.w3c.dom.Element;
  
  import java.util.HashMap;
  
  
  public class AppenderAction extends Action {
    static final Logger logger = Logger.getLogger(AppenderAction.class);
    Appender appender;
  
    /**
     * Instantiates an appender of the given class and sets its name.
     *
     * The appender thus generated is placed in the ExecutionContext appender bag.
     */
    public void begin(ExecutionContext ec, Element appenderElement) {
      String className =
        appenderElement.getAttribute(CLASS_ATTRIBUTE);
  
      try {
        logger.debug(
          "About to instantiate appender of type [" + className + "]");
  
        Object instance =
          OptionConverter.instantiateByClassName(
            className, org.apache.log4j.Appender.class, null);
        appender = (Appender) instance;
  
        String appenderName =
          appenderElement.getAttribute(NAME_ATTRIBUTE);
  
        if (Option.isEmpty(appenderName)) {
          logger.warn(
            "No appender name given for appender of type " + className + "].");
        } else {
          appender.setName(appenderName);
          logger.debug("Appender named as [" + appenderName + "]");
        }
  
        HashMap appenderBag =
          (HashMap) ec.getObjectMap().get(ActionConst.APPENDER_BAG);
        appenderBag.put(appenderName, appender);
  
        logger.debug("Pushing appender on to the object stack.");
        ec.pushObject(appender);
      } catch (Exception oops) {
        inError = true;
        logger.error(
          "Could not create an Appender. Reported error follows.", oops);
        ec.addError("Could not create appender of type " + className + "].");
      }
    }
  
    /**
     * Once the children elements are also parsed, now is the time to activate
     * the appender options.
     */
    public void end(ExecutionContext ec, Element e) {
      if (inError) {
        return;
      }
  
      if (appender instanceof OptionHandler) {
        ((OptionHandler) appender).activateOptions();
      }
  
      Object o = ec.peekObject();
  
      if (o != appender) {
        logger.warn(
          "The object at the of the stack is not the appender named ["
          + appender.getName() + "] pushed earlier.");
      } else {
        logger.warn(
          "Popping appender named [" + appender.getName()
          + "] from the object stack");
        ec.popObject();
      }
    }
  
    public void finish(ExecutionContext ec) {
    }
  }
  
  
  
  1.1                  jakarta-log4j/src/java/org/apache/log4j/joran/action/RootLoggerAction.java
  
  Index: RootLoggerAction.java
  ===================================================================
  /*
   * ============================================================================
   *                   The Apache Software License, Version 1.1
   * ============================================================================
   *
   *    Copyright (C) 1999 The Apache Software Foundation. All rights reserved.
   *
   * Redistribution and use in source and binary forms, with or without modifica-
   * tion, are permitted provided that the following conditions are met:
   *
   * 1. Redistributions of  source code must  retain the above copyright  notice,
   *    this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright notice,
   *    this list of conditions and the following disclaimer in the documentation
   *    and/or other materials provided with the distribution.
   *
   * 3. The end-user documentation included with the redistribution, if any, must
   *    include  the following  acknowledgment:  "This product includes  software
   *    developed  by the  Apache Software Foundation  (http://www.apache.org/)."
   *    Alternately, this  acknowledgment may  appear in the software itself,  if
   *    and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "log4j" and  "Apache Software Foundation"  must not be used to
   *    endorse  or promote  products derived  from this  software without  prior
   *    written permission. For written permission, please contact
   *    apache@apache.org.
   *
   * 5. Products  derived from this software may not  be called "Apache", nor may
   *    "Apache" appear  in their name,  without prior written permission  of the
   *    Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
   * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
   * FITNESS  FOR A PARTICULAR  PURPOSE ARE  DISCLAIMED.  IN NO  EVENT SHALL  THE
   * APACHE SOFTWARE  FOUNDATION  OR ITS CONTRIBUTORS  BE LIABLE FOR  ANY DIRECT,
   * INDIRECT, INCIDENTAL, SPECIAL,  EXEMPLARY, OR CONSEQUENTIAL  DAMAGES (INCLU-
   * DING, BUT NOT LIMITED TO, PROCUREMENT  OF SUBSTITUTE GOODS OR SERVICES; LOSS
   * OF USE, DATA, OR  PROFITS; OR BUSINESS  INTERRUPTION)  HOWEVER CAUSED AND ON
   * ANY  THEORY OF LIABILITY,  WHETHER  IN CONTRACT,  STRICT LIABILITY,  OR TORT
   * (INCLUDING  NEGLIGENCE OR  OTHERWISE) ARISING IN  ANY WAY OUT OF THE  USE OF
   * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
   *
   * This software  consists of voluntary contributions made  by many individuals
   * on  behalf of the Apache Software  Foundation.  For more  information on the
   * Apache Software Foundation, please see <http://www.apache.org/>.
   *
   */
  
  package org.apache.log4j.joran.action;
  
  import org.apache.joran.ExecutionContext;
  import org.apache.joran.action.Action;
  
  import org.apache.log4j.Logger;
  import org.apache.log4j.spi.LoggerRepository;
  
  import org.w3c.dom.Element;
  
  
  public class RootLoggerAction extends Action {
    static final String NAME_ATTR = "name";
    static final String CLASS_ATTR = "class";
    static final String ADDITIVITY_ATTR = "additivity";
    static final String EMPTY_STR = "";
    static final Class[] ONE_STRING_PARAM = new Class[] { String.class };
    Logger logger = Logger.getLogger(RootLoggerAction.class);
    Logger root;
  
    public void begin(ExecutionContext ec, Element loggerElement) {
      inError = false;
      logger.debug("In begin method");
  
      LoggerRepository repository = (LoggerRepository) ec.getObject(0);
      root = repository.getRootLogger();
  
      logger.debug("Pushing root logger on stack");
      ec.pushObject(root);
    }
  
    public void end(ExecutionContext ec, Element e) {
      logger.debug("end() called.");
  
      if (inError) {
        return;
      }
  
      Object o = ec.peekObject();
  
      if (o != root) {
        logger.warn(
          "The object on the top the of the stack is not the root logger");
          logger.warn("It is: "+o);
      } else {
        logger.debug("Removing root logger from top of stack.");
        ec.popObject();
      }
    }
  
    public void finish(ExecutionContext ec) {
    }
  }
  
  
  
  1.1                  jakarta-log4j/src/java/org/apache/log4j/joran/action/LayoutAction.java
  
  Index: LayoutAction.java
  ===================================================================
  /*
   * ============================================================================
   *                   The Apache Software License, Version 1.1
   * ============================================================================
   *
   *    Copyright (C) 1999 The Apache Software Foundation. All rights reserved.
   *
   * Redistribution and use in source and binary forms, with or without modifica-
   * tion, are permitted provided that the following conditions are met:
   *
   * 1. Redistributions of  source code must  retain the above copyright  notice,
   *    this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright notice,
   *    this list of conditions and the following disclaimer in the documentation
   *    and/or other materials provided with the distribution.
   *
   * 3. The end-user documentation included with the redistribution, if any, must
   *    include  the following  acknowledgment:  "This product includes  software
   *    developed  by the  Apache Software Foundation  (http://www.apache.org/)."
   *    Alternately, this  acknowledgment may  appear in the software itself,  if
   *    and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "log4j" and  "Apache Software Foundation"  must not be used to
   *    endorse  or promote  products derived  from this  software without  prior
   *    written permission. For written permission, please contact
   *    apache@apache.org.
   *
   * 5. Products  derived from this software may not  be called "Apache", nor may
   *    "Apache" appear  in their name,  without prior written permission  of the
   *    Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
   * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
   * FITNESS  FOR A PARTICULAR  PURPOSE ARE  DISCLAIMED.  IN NO  EVENT SHALL  THE
   * APACHE SOFTWARE  FOUNDATION  OR ITS CONTRIBUTORS  BE LIABLE FOR  ANY DIRECT,
   * INDIRECT, INCIDENTAL, SPECIAL,  EXEMPLARY, OR CONSEQUENTIAL  DAMAGES (INCLU-
   * DING, BUT NOT LIMITED TO, PROCUREMENT  OF SUBSTITUTE GOODS OR SERVICES; LOSS
   * OF USE, DATA, OR  PROFITS; OR BUSINESS  INTERRUPTION)  HOWEVER CAUSED AND ON
   * ANY  THEORY OF LIABILITY,  WHETHER  IN CONTRACT,  STRICT LIABILITY,  OR TORT
   * (INCLUDING  NEGLIGENCE OR  OTHERWISE) ARISING IN  ANY WAY OUT OF THE  USE OF
   * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
   *
   * This software  consists of voluntary contributions made  by many individuals
   * on  behalf of the Apache Software  Foundation.  For more  information on the
   * Apache Software Foundation, please see <http://www.apache.org/>.
   *
   */
  
  package org.apache.log4j.joran.action;
  
  import org.apache.joran.ExecutionContext;
  import org.apache.joran.action.Action;
  
  import org.apache.log4j.Appender;
  import org.apache.log4j.Layout;
  import org.apache.log4j.Logger;
  import org.apache.log4j.helpers.OptionConverter;
  import org.apache.log4j.spi.OptionHandler;
  
  import org.w3c.dom.Element;
  
  
  public class LayoutAction extends Action {
    static final Logger logger = Logger.getLogger(LayoutAction.class);
    Layout layout;
  
    /**
     * Instantiates an layout of the given class and sets its name.
     *
     */
    public void begin(ExecutionContext ec, Element appenderElement) {
  		// Let us forget about previous errors (in this object)
  		inError = false; 
  
      String className =
        appenderElement.getAttribute(CLASS_ATTRIBUTE);
      try {
        logger.debug("About to instantiate layout of type [" + className + "]");
  
        Object instance =
          OptionConverter.instantiateByClassName(
            className, org.apache.log4j.Layout.class, null);
        layout = (Layout) instance;
  
        logger.debug("Pushing layout on top of the object stack.");
        ec.pushObject(layout);
      } catch (Exception oops) {
        inError = true;
        logger.error(
          "Could not create an Layout. Reported error follows.", oops);
        ec.addError("Could not create layout of type " + className + "].");
      }
    }
  
    /**
     * Once the children elements are also parsed, now is the time to activate
     * the appender options.
     */
    public void end(ExecutionContext ec, Element e) {
      if (inError) {
        return;
      }
  
      if (layout instanceof OptionHandler) {
        ((OptionHandler) layout).activateOptions();
      }
  
      Object o = ec.peekObject();
  
      if (o != layout) {
        logger.warn(
          "The object on the top the of the stack is not the layout pushed earlier.");
      } else {
        logger.warn("Popping layout from the object stack");
        ec.popObject();
        
        try {
        	logger.debug("About to set the layout of the containing appender.");
          Appender appender = (Appender) ec.peekObject();
          appender.setLayout(layout);
        } catch(Exception ex) {
        	logger.error("Could not set the layout for containing appender.", ex);
        }
      }
    }
  
    public void finish(ExecutionContext ec) {
    }
  }
  
  
  
  1.7       +9 -9      jakarta-log4j/tests/src/java/org/apache/joran/JoranParserTest.java
  
  Index: JoranParserTest.java
  ===================================================================
  RCS file: /home/cvs/jakarta-log4j/tests/src/java/org/apache/joran/JoranParserTest.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- JoranParserTest.java	23 Sep 2003 19:45:58 -0000	1.6
  +++ JoranParserTest.java	25 Sep 2003 09:28:18 -0000	1.7
  @@ -57,23 +57,23 @@
   
   import junit.framework.TestCase;
   
  -import org.apache.joran.action.ActionConst;
  -import org.apache.joran.action.AppenderAction;
  -import org.apache.joran.action.AppenderRefAction;
  -import org.apache.joran.action.ConversionRuleAction;
  -import org.apache.joran.action.LayoutAction;
  -import org.apache.joran.action.LevelAction;
  -import org.apache.joran.action.LoggerAction;
   import org.apache.joran.action.NestComponentIA;
   import org.apache.joran.action.NewRuleAction;
   import org.apache.joran.action.ParamAction;
  -import org.apache.joran.action.RootLoggerAction;
   
   import org.apache.log4j.Appender;
   import org.apache.log4j.ConsoleAppender;
   import org.apache.log4j.LogManager;
   import org.apache.log4j.Logger;
   import org.apache.log4j.PatternLayout;
  +import org.apache.log4j.joran.action.ActionConst;
  +import org.apache.log4j.joran.action.AppenderAction;
  +import org.apache.log4j.joran.action.AppenderRefAction;
  +import org.apache.log4j.joran.action.ConversionRuleAction;
  +import org.apache.log4j.joran.action.LayoutAction;
  +import org.apache.log4j.joran.action.LevelAction;
  +import org.apache.log4j.joran.action.LoggerAction;
  +import org.apache.log4j.joran.action.RootLoggerAction;
   
   import org.w3c.dom.Document;
   
  @@ -230,7 +230,7 @@
       jp.parse(doc);
     }
   
  -  public void xtestNewConversionWord() throws Exception {
  +  public void testNewConversionWord() throws Exception {
       logger.debug("Starting testNewConversionWord");
   
       DocumentBuilderFactory dbf = null;
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: log4j-dev-help@jakarta.apache.org


Mime
View raw message