You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@turbine.apache.org by do...@apache.org on 2002/04/05 09:04:56 UTC

cvs commit: jakarta-turbine-2/src/java/org/apache/turbine/services/logging Log4JavaLogger.java LoggingConfig.java PropertiesLoggingConfig.java TurbineLoggingService.java

dobbs       02/04/04 23:04:55

  Modified:    src/java/org/apache/turbine/services/logging
                        Log4JavaLogger.java LoggingConfig.java
                        PropertiesLoggingConfig.java
                        TurbineLoggingService.java
  Log:
  applied patches from Chris Kimpton.  He has this to say about them:
  
  I chose to effectively backport what
  torque and fulcrum do, that is, use log4j properties directly, for
  example:
  
  # An example configuration for using Log4Java, with log4j properties
  inline
  # The category name - at the end of this line - needs to match the
  logging facility name - the first log4j.
  # need this rootCategory entry to capture the torque/fulcrum etc
  logging
  services.LoggingService.logforj.log4j.rootCategory = DEBUG, logforj
  # need this category entry for the actual jetspeed logging (I don't
  know why it doesn't get covered by the root category!)
  services.LoggingService.logforj.log4j.category.logforj = DEBUG,
  logforj
  services.LoggingService.logforj.log4j.appender.logforj.file
  =${webappRoot}/WEB-INF/log/jetspeed_log4j.log
  services.LoggingService.logforj.log4j.appender.logforj =
  org.apache.log4j.FileAppender
  services.LoggingService.logforj.log4j.appender.logforj.layout =
  org.apache.log4j.PatternLayout
  services.LoggingService.logforj.log4j.appender.logforj.layout.conversionPattern
  = [%d{ABSOLUTE} %-5p] %m%n
  services.LoggingService.logforj.log4j.appender.logforj.append = false
  services.LoggingService.logforj.className=org.apache.turbine.services.logging.Log4JavaLogger
  services.LoggingService.logforj.level=DEBUG
  
  This gives the full flexibility of log4j - in particular allows for
  merging the torque et al logs into one, while keeping the turbine
  TR.props configuration of it.
  
  This patch relies on the stratum patches submitted earlier - in
  particular for the interpolate additions relating to getStringArray
  and subset.
  
  Revision  Changes    Path
  1.3       +21 -10    jakarta-turbine-2/src/java/org/apache/turbine/services/logging/Log4JavaLogger.java
  
  Index: Log4JavaLogger.java
  ===================================================================
  RCS file: /home/cvs/jakarta-turbine-2/src/java/org/apache/turbine/services/logging/Log4JavaLogger.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- Log4JavaLogger.java	10 Jan 2002 18:57:54 -0000	1.2
  +++ Log4JavaLogger.java	5 Apr 2002 07:04:55 -0000	1.3
  @@ -54,21 +54,14 @@
    * <http://www.apache.org/>.
    */
   
  -import java.io.IOException;
  -import java.io.OutputStream;
  -import java.io.PrintStream;
  -import java.util.Enumeration;
  -import java.util.Hashtable;
  -import java.util.Vector;
  -import javax.servlet.ServletContext;
   import org.apache.log4j.Appender;
  -import org.apache.log4j.AppenderSkeleton;
   import org.apache.log4j.Category;
  -import org.apache.log4j.WriterAppender;
   import org.apache.log4j.Layout;
   import org.apache.log4j.PatternLayout;
   import org.apache.log4j.Priority;
  +import org.apache.log4j.PropertyConfigurator;
   import org.apache.log4j.RollingFileAppender;
  +import org.apache.log4j.WriterAppender;
   import org.apache.log4j.net.SMTPAppender;
   import org.apache.log4j.net.SocketAppender;
   import org.apache.log4j.net.SyslogAppender;
  @@ -76,6 +69,12 @@
   import org.apache.turbine.services.resources.TurbineResources;
   import org.apache.turbine.util.RunData;
   
  +import javax.servlet.ServletContext;
  +import java.util.Enumeration;
  +import java.util.Hashtable;
  +import java.util.Properties;
  +import java.util.Vector;
  +
   /**
    * Class implements the Logger interface using log4java package
    * Messages can be written to following destination:
  @@ -93,7 +92,7 @@
    * @author <a href="mailto:jon@latchkey.com">Jon S. Stevens</a>
    * @author <a href="mailto:sean@informage.net">Sean Legassick</a>
    * @author <a href="mailto:jvanzyl@apache.org">Jason van Zyl</a>
  - * @version $Id: Log4JavaLogger.java,v 1.2 2002/01/10 18:57:54 dlr Exp $
  + * @version $Id: Log4JavaLogger.java,v 1.3 2002/04/05 07:04:55 dobbs Exp $
    */
   public class Log4JavaLogger extends BaseLogger
   {
  @@ -135,6 +134,11 @@
   
           // now do the rest of initialization
           super.init(loggingConfig);
  +
  +        //if there are log4j properties defined, let them override all else
  +        Properties props =
  +            loggingConfig.getFacilityProperties(loggingConfig.getName());
  +        PropertyConfigurator.configure(props);
       }
   
   
  @@ -146,6 +150,13 @@
       protected void configureFiles(LoggingConfig loggingConfig)
       {
           Vector files = loggingConfig.getFiles();
  +
  +        //we may not always have 'files' defined, for example if its
  +        //done in the log4j properties
  +        if (files == null)
  +        {
  +            return;
  +        }
   
           for (Enumeration filesEnum = files.elements(); filesEnum.hasMoreElements(); )
           {
  
  
  
  1.2       +8 -1      jakarta-turbine-2/src/java/org/apache/turbine/services/logging/LoggingConfig.java
  
  Index: LoggingConfig.java
  ===================================================================
  RCS file: /home/cvs/jakarta-turbine-2/src/java/org/apache/turbine/services/logging/LoggingConfig.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- LoggingConfig.java	16 Aug 2001 05:09:04 -0000	1.1
  +++ LoggingConfig.java	5 Apr 2002 07:04:55 -0000	1.2
  @@ -55,6 +55,7 @@
    */
   
   import java.util.Vector;
  +import java.util.Properties;
   import org.apache.turbine.services.InitializationException;
   
   /**
  @@ -63,7 +64,7 @@
    * system.
    *
    * @author <a href="mailto:jon@latchkey.com">Jon S. Stevens</a>
  - * @version $Id: LoggingConfig.java,v 1.1 2001/08/16 05:09:04 jvanzyl Exp $
  + * @version $Id: LoggingConfig.java,v 1.2 2002/04/05 07:04:55 dobbs Exp $
    */
   public interface LoggingConfig
   {
  @@ -81,6 +82,12 @@
       public static final int DEFAULT_BACKUP_FILES = 1;
   
       public abstract void setInitResource(Object props);
  +
  +    /**
  +     * returns all properties in a properties object - used by log4j
  +     * initialization
  +     **/
  +    public abstract Properties getFacilityProperties(String facilityName);
   
       public abstract void init() throws InitializationException;
   
  
  
  
  1.2       +51 -1     jakarta-turbine-2/src/java/org/apache/turbine/services/logging/PropertiesLoggingConfig.java
  
  Index: PropertiesLoggingConfig.java
  ===================================================================
  RCS file: /home/cvs/jakarta-turbine-2/src/java/org/apache/turbine/services/logging/PropertiesLoggingConfig.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- PropertiesLoggingConfig.java	16 Aug 2001 05:09:04 -0000	1.1
  +++ PropertiesLoggingConfig.java	5 Apr 2002 07:04:55 -0000	1.2
  @@ -56,8 +56,12 @@
   
   import java.util.Iterator;
   import java.util.Vector;
  +import java.util.Properties;
  +
   import org.apache.turbine.services.InitializationException;
   import org.apache.turbine.services.resources.ResourceService;
  +import org.apache.turbine.util.Log;
  +import org.apache.stratum.configuration.Configuration;
   
   /**
    * Small helper class that encapsulates the logging configuration 
  @@ -65,7 +69,7 @@
    * file.
    *
    * @author <a href="mailto:jon@latchkey.com">Jon S. Stevens</a>
  - * @version $Id: PropertiesLoggingConfig.java,v 1.1 2001/08/16 05:09:04 jvanzyl Exp $
  + * @version $Id: PropertiesLoggingConfig.java,v 1.2 2002/04/05 07:04:55 dobbs Exp $
    */
   public class PropertiesLoggingConfig implements LoggingConfig
   {
  @@ -103,6 +107,52 @@
       public void setInitResource (Object props)
       {
           this.props = (ResourceService) props;
  +    }
  +
  +    /** 
  +     * returns all properties in a properties object - used by log4j
  +     * initialization
  +     **/
  +    public Properties getFacilityProperties(String facilityName)
  +    {
  +        // Extract the log4j values out of the configuration and
  +        // place them in a Properties object so that we can
  +        // use the log4j PropertyConfigurator.
  +        Properties p = new Properties();
  +
  +        Configuration facilityConfiguration =
  +            props.getConfiguration(facilityName);
  +        Iterator i = facilityConfiguration.getKeys();
  +        while (i.hasNext())
  +        {
  +            String key = (String) i.next();
  +
  +            // We have to deal with ExtendedProperties way
  +            // of dealing with "," in properties which is to
  +            // make them separate values. Log4j category
  +            // properties contain commas so we must stick them
  +            // back together for log4j.
  +            String[] values = facilityConfiguration.getStringArray(key);
  +
  +            String value = null;
  +            if (values.length == 1)
  +            {
  +                value = values[0];
  +            }
  +            else if (values.length > 1)
  +            {
  +                StringBuffer valueSB = new StringBuffer();
  +                for (int j=0; j<values.length-1; j++)
  +                {
  +                    valueSB.append(values[j]).append(",");
  +                }
  +                value = valueSB.append(values[values.length-1]).toString();
  +            }
  +
  +            p.put(key, value);
  +        }
  +
  +        return p;
       }
   
       public void init()
  
  
  
  1.3       +8 -1      jakarta-turbine-2/src/java/org/apache/turbine/services/logging/TurbineLoggingService.java
  
  Index: TurbineLoggingService.java
  ===================================================================
  RCS file: /home/cvs/jakarta-turbine-2/src/java/org/apache/turbine/services/logging/TurbineLoggingService.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- TurbineLoggingService.java	28 Aug 2001 16:28:34 -0000	1.2
  +++ TurbineLoggingService.java	5 Apr 2002 07:04:55 -0000	1.3
  @@ -65,6 +65,7 @@
   import org.apache.turbine.services.resources.ResourceService;
   import org.apache.turbine.services.resources.TurbineResources;
   import org.apache.turbine.util.RunData;
  +import org.apache.turbine.Turbine;
   
   /**
    * The default implementation of the logging service in Turbine.
  @@ -81,7 +82,7 @@
    * @see org.apache.turbine.services.logging.Logger
    * @author <a href="mailto:Tomasz.Zielinski@e-point.pl">Tomasz Zielinski</a>
    * @author <a href="mailto:jon@latchkey.com">Jon S. Stevens</a>
  - * @version $Id: TurbineLoggingService.java,v 1.2 2001/08/28 16:28:34 jvanzyl Exp $
  + * @version $Id: TurbineLoggingService.java,v 1.3 2002/04/05 07:04:55 dobbs Exp $
    */
   public class TurbineLoggingService
       extends TurbineBaseService
  @@ -191,6 +192,12 @@
               resources = TurbineResources
                   .getResources(TurbineServices.SERVICE_PREFIX +
                   LoggingService.SERVICE_NAME);
  +
  +            //add webappRoot manually - cos logging is a primary
  +            //service and so it is not yet defined
  +            String webappRoot = context.getRealPath("");
  +            resources.setProperty(Turbine.WEBAPP_ROOT,webappRoot);
  +
           }
           return (resources);
       }
  
  
  

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>