db-ojb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From arm...@apache.org
Subject cvs commit: db-ojb/src/java/org/apache/ojb/broker/util/logging LoggerFactoryImpl.java LoggingConfiguration.java
Date Wed, 09 Nov 2005 01:17:00 GMT
arminw      2005/11/08 17:17:00

  Modified:    src/java/org/apache/ojb/broker/util/logging
                        LoggerFactoryImpl.java LoggingConfiguration.java
  Log:
  apply patch by Patrick Byrne:
  Attached is a patch for Logging Configuration. The problem was that the properties specified
as arguments to Java from command line (running standalone as opposed to in Tomcat app server)
were not being picked up properly.
  
  change Boot-Logger level from WARN to INFO to force OJB printing information about the used
logging configuration at startup, the default log-level is still WARN.
  
  Revision  Changes    Path
  1.23      +6 -5      db-ojb/src/java/org/apache/ojb/broker/util/logging/LoggerFactoryImpl.java
  
  Index: LoggerFactoryImpl.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/util/logging/LoggerFactoryImpl.java,v
  retrieving revision 1.22
  retrieving revision 1.23
  diff -u -r1.22 -r1.23
  --- LoggerFactoryImpl.java	7 Oct 2005 14:54:48 -0000	1.22
  +++ LoggerFactoryImpl.java	9 Nov 2005 01:17:00 -0000	1.23
  @@ -29,9 +29,7 @@
    *
    * @author Thomas Mahler
    * @author <a href="leandro@ibnetwork.com.br">Leandro Rodrigo Saad Cruz</a>
  - *
    * @version $Id$
  - *
    * @see <a href="http://jakarta.apache.org/log4j/docs/index.html">jakarta-log4j</a>
    */
   public class LoggerFactoryImpl
  @@ -72,6 +70,7 @@
        * returns a minimal logger that needs no configuration
        * and can thus be safely used during OJB boot phase
        * (i.e. when OJB.properties have not been loaded).
  +     *
        * @return Logger the OJB BootLogger
        */
       public Logger getBootLogger()
  @@ -80,7 +79,7 @@
           {
               bootLogger = new PoorMansLoggerImpl("BOOT", null);
               // allow user to set boot log level via system property
  -            String level = System.getProperty("OJB.bootLogLevel", LoggingConfiguration.OJB_DEFAULT_LOG_LEVEL);
  +            String level = System.getProperty("OJB.bootLogLevel", LoggingConfiguration.OJB_DEFAULT_BOOT_LOG_LEVEL);
               ((PoorMansLoggerImpl) bootLogger).setLevel(level);
           }
           return bootLogger;
  @@ -91,6 +90,7 @@
        * returns the default logger. This Logger can
        * be used when it is not appropriate to use a
        * dedicated fresh Logger instance.
  +     *
        * @return default Logger
        */
       public Logger getDefaultLogger()
  @@ -106,6 +106,7 @@
       /**
        * returns a Logger. The Logger is named
        * after the full qualified name of input parameter clazz
  +     *
        * @param clazz the Class which name is to be used as name
        * @return Logger the returned Logger
        */
  @@ -117,6 +118,7 @@
   
       /**
        * returns a Logger.
  +     *
        * @param loggerName the name of the Logger
        * @return Logger the returned Logger
        */
  @@ -152,5 +154,4 @@
           }
           return logger;
       }
  -
   }
  
  
  
  1.12      +37 -18    db-ojb/src/java/org/apache/ojb/broker/util/logging/LoggingConfiguration.java
  
  Index: LoggingConfiguration.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/util/logging/LoggingConfiguration.java,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- LoggingConfiguration.java	15 Jul 2005 15:01:39 -0000	1.11
  +++ LoggingConfiguration.java	9 Nov 2005 01:17:00 -0000	1.12
  @@ -16,9 +16,12 @@
    */
   
   import java.io.InputStream;
  +import java.io.File;
   import java.util.Properties;
  +import java.net.URL;
   
   import org.apache.ojb.broker.util.ClassHelper;
  +import org.apache.commons.lang.SystemUtils;
   
   /**
    * Provides the configuration for the logging. Note that this is separated from the OJB
  @@ -42,6 +45,8 @@
       public static final String OJB_LOGGING_PROPERTIES_FILE = "OJB-logging.properties";
       /** Default log level */
       public static final String OJB_DEFAULT_LOG_LEVEL = "WARN";
  +    /** Default boot log level */
  +    public static final String OJB_DEFAULT_BOOT_LOG_LEVEL = "INFO";
   
       /** The logger class */
       private Class  _loggerClass;
  @@ -69,38 +74,52 @@
           //   org.apache.ojb.broker.util.logging.Logger
           // is set (or its alias LoggerClass which is deprecated)
           ClassLoader contextLoader   = ClassHelper.getClassLoader();
  -        String      loggerClassName = null;
  +        String      loggerClassName;
   
           _loggerClass      = null;
           _properties       = new Properties();
           loggerClassName   = getLoggerClass(System.getProperties());
           _loggerConfigFile = getLoggerConfigFile(System.getProperties());
   
  -        InputStream ojbLogPropFile = null;
  +        InputStream ojbLogPropFile;
           if (loggerClassName == null)
           {
               // now we're trying to load the OJB-logging.properties file
  -            String ojbLoggingPropFile = System.getProperty(OJB_LOGGING_PROPERTIES_FILE,
OJB_LOGGING_PROPERTIES_FILE);
  +            String ojbLogPropFilePath = System.getProperty(OJB_LOGGING_PROPERTIES_FILE,
OJB_LOGGING_PROPERTIES_FILE);
               try
               {
  -                ojbLogPropFile = contextLoader.getResourceAsStream(ojbLoggingPropFile);
  -                if (ojbLogPropFile != null)
  +                URL ojbLoggingURL = ClassHelper.getResource(ojbLogPropFilePath);
  +                if (ojbLoggingURL == null)
                   {
  -                    try
  -                    {
  -                        bootLogger.info("Found logging properties file: "+ojbLoggingPropFile);
  -                        _properties.load(ojbLogPropFile);
  -                        loggerClassName   = getLoggerClass(_properties);
  -                        _loggerConfigFile = getLoggerConfigFile(_properties);
  -                    }
  -                    finally
  -                    {
  -                        ojbLogPropFile.close();
  -                    }
  +                    ojbLoggingURL = (new File(ojbLogPropFilePath)).toURL();
  +                }
  +                ojbLogPropFile = ojbLoggingURL.openStream();
  +                try
  +                {
  +                    bootLogger.info("Found logging properties file: " + ojbLogPropFilePath);
  +                    _properties.load(ojbLogPropFile);
  +                    _loggerConfigFile = getLoggerConfigFile(_properties);
  +                    loggerClassName = getLoggerClass(_properties);
  +                }
  +                finally
  +                {
  +                    ojbLogPropFile.close();
                   }
               }
               catch (Exception ex)
  -            {}
  +            {
  +                if(loggerClassName == null)
  +                {
  +                    bootLogger.warn("Can't read logging properties file using path '" +
ojbLogPropFilePath
  +                            + "', message is: " + SystemUtils.LINE_SEPARATOR + ex.getMessage()
  +                            + SystemUtils.LINE_SEPARATOR + "Will try to load logging properties
from OJB.properties file");
  +                }
  +                else
  +                {
  +                    bootLogger.info("Problems while closing resources for path '" + ojbLogPropFilePath
  +                            + "', message is: " + SystemUtils.LINE_SEPARATOR + ex.getMessage(),
ex);
  +                }
  +            }
           }
           if (loggerClassName == null)
           {
  
  
  

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


Mime
View raw message