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:02:37 GMT
arminw      2005/11/08 17:02:37

  Modified:    src/java/org/apache/ojb/broker/util/logging Tag:
                        OJB_1_0_RELEASE 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
  No                   revision
  No                   revision
  1.18.2.3  +2 -2      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.18.2.2
  retrieving revision 1.18.2.3
  diff -u -r1.18.2.2 -r1.18.2.3
  --- LoggerFactoryImpl.java	9 Oct 2005 23:54:05 -0000	1.18.2.2
  +++ LoggerFactoryImpl.java	9 Nov 2005 01:02:37 -0000	1.18.2.3
  @@ -79,7 +79,7 @@
           {
               bootLogger = new PoorMansLoggerImpl("BOOT");
               // 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;
  
  
  
  1.8.2.3   +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.8.2.2
  retrieving revision 1.8.2.3
  diff -u -r1.8.2.2 -r1.8.2.3
  --- LoggingConfiguration.java	15 Jul 2005 15:00:59 -0000	1.8.2.2
  +++ LoggingConfiguration.java	9 Nov 2005 01:02:37 -0000	1.8.2.3
  @@ -16,10 +16,13 @@
    */
   
   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.ojb.broker.util.configuration.impl.ConfigurationAbstractImpl;
  +import org.apache.commons.lang.SystemUtils;
   
   /**
    * Provides the configuration for the logging. Note that this is separated from the OJB
  @@ -43,6 +46,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;
  @@ -68,38 +73,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