db-ojb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From to...@apache.org
Subject cvs commit: db-ojb/src/test/org/apache/ojb OJB-logging.properties OJB.properties
Date Tue, 01 Jun 2004 21:42:21 GMT
tomdz       2004/06/01 14:42:21

  Modified:    src/java/org/apache/ojb/broker/util/logging
                        LoggerFactoryImpl.java Log4jLoggerImpl.java
                        Logger.java LoggingConfiguration.java
               src/java/org/apache/ojb/broker/util/configuration/impl
                        ConfigurationAbstractImpl.java
                        OjbConfiguration.java
               src/test/org/apache/ojb OJB.properties
  Added:       src/test/org/apache/ojb OJB-logging.properties
  Log:
  Separated logging properties/initialization from OJB properties/initialization
  
  Revision  Changes    Path
  1.15      +15 -40    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.14
  retrieving revision 1.15
  diff -u -r1.14 -r1.15
  --- LoggerFactoryImpl.java	4 Apr 2004 23:53:38 -0000	1.14
  +++ LoggerFactoryImpl.java	1 Jun 2004 21:42:21 -0000	1.15
  @@ -15,14 +15,10 @@
    * limitations under the License.
    */
   
  -//OJB
  -
   import java.util.HashMap;
   import java.util.Map;
   
   import org.apache.ojb.broker.util.ClassHelper;
  -import org.apache.ojb.broker.util.configuration.Configurator;
  -import org.apache.ojb.broker.util.configuration.impl.OjbConfigurator;
   
   /**
    * The factory class <code>LoggerFactory</code> can be used
  @@ -71,6 +67,7 @@
       {
           if (bootLogger == null)
           {
  +            // TODO: replace this with commons-logging
               bootLogger = new PoorMansLoggerImpl("BOOT");
               // allow user to set boot log level via system property
               String level = System.getProperty("OJB.bootLogLevel", "WARN");
  @@ -118,54 +115,32 @@
           //lookup in the cache first
           if (cache.containsKey(loggerName))
           {
  -            getBootLogger().debug("Returning cached version of Logger[" + loggerName +
"]");
  +            //getBootLogger().debug("Returning cached version of Logger[" + loggerName
+ "]");
               return (Logger) cache.get(loggerName);
           }
  -        getBootLogger().debug("Logger[" + loggerName + "] not cached");
  +        //getBootLogger().debug("Logger[" + loggerName + "] not cached");
   
           Logger logger = null;
           Class loggerClass = null;
           try
           {
  -            // obtain configurator
  -            Configurator configurator = OjbConfigurator.getInstance();
  -
  -            // get the configuration
  -            LoggingConfiguration lc = (LoggingConfiguration) configurator.getConfigurationFor(null);
  +            // get the configuration (not from the configurator because this is independent)
  +            LoggingConfiguration conf = new LoggingConfiguration();
   
  -            loggerClass = lc.getLoggerClass();
  -            getBootLogger().debug("Using logger class : " + loggerClass + " for:" + loggerName);
  +            loggerClass = conf.getLoggerClass();
  +            getBootLogger().debug("Using logger class " + loggerClass + " for " + loggerName);
               logger = (Logger) ClassHelper.newInstance(loggerClass, String.class, loggerName);
   
               // configure the logger
  -            if (logger instanceof Log4jLoggerImpl)
  -            {
  -                getBootLogger().debug("Initializing Log4j logger instance " + loggerName);
  -                logger.configure(lc);
  -            }
  -            else if (logger instanceof PoorMansLoggerImpl)
  +            try
               {
  -                getBootLogger().debug("Initializing PoorMans logger instance " + loggerName);
  -                logger.configure(lc);
  -            }
  -            else if (logger instanceof CommonsLoggerImpl)
  -            {
  -                getBootLogger().debug("Initializing Commons logger instance " + loggerName);
  -
  -                logger.configure(lc);
  +                getBootLogger().debug("Initializing logger instance " + loggerName);
  +                logger.configure(conf);
               }
  -            else
  +            catch (Exception ex)
               {
  -                // try to initialize a custom logger
  -                try
  -                {
  -                    getBootLogger().debug("Initializing Custom logger instance " + loggerName);
  -                    logger.configure(lc);
  -                }
  -                catch (Exception x)
  -                {
  -                    throw new IllegalArgumentException("Don't know how to initialize :
" + logger);
  -                }
  +                logger = getBootLogger();
  +                logger.error("[" + this.getClass().getName() + "] Could not initialize
logger for class " + loggerClass.getName(), ex);
               }
   
               //cache it so we can get it faster the next time
  @@ -174,7 +149,7 @@
           catch (Throwable t)
           {
               logger = getBootLogger();
  -            logger.error("[" + this.getClass().getName() + "]   Could not set logger for
class " + loggerClass, t);
  +            logger.error("[" + this.getClass().getName() + "] Could not set logger for
class " + loggerClass.getName(), t);
           }
           return logger;
       }
  
  
  
  1.16      +3 -2      db-ojb/src/java/org/apache/ojb/broker/util/logging/Log4jLoggerImpl.java
  
  Index: Log4jLoggerImpl.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/util/logging/Log4jLoggerImpl.java,v
  retrieving revision 1.15
  retrieving revision 1.16
  diff -u -r1.15 -r1.16
  --- Log4jLoggerImpl.java	22 May 2004 11:23:36 -0000	1.15
  +++ Log4jLoggerImpl.java	1 Jun 2004 21:42:21 -0000	1.16
  @@ -22,6 +22,7 @@
   import org.apache.log4j.LogManager;
   import org.apache.log4j.Level;
   import org.apache.log4j.PropertyConfigurator;
  +import org.apache.ojb.broker.util.ClassHelper;
   import org.apache.ojb.broker.util.configuration.Configuration;
   import org.apache.ojb.broker.util.configuration.ConfigurationException;
   
  @@ -105,7 +106,7 @@
           if (configFile != null)
           {
               // try resource look in classpath
  -            URL url = Thread.currentThread().getContextClassLoader().getResource(configFile);
  +            URL url = ClassHelper.getResource(configFile);
               LoggerFactory.getBootLogger().info("Initializing Log4J : resource from config
file:" + url);
               if (url != null)
               {
  
  
  
  1.9       +1 -1      db-ojb/src/java/org/apache/ojb/broker/util/logging/Logger.java
  
  Index: Logger.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/util/logging/Logger.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- Logger.java	5 Apr 2004 12:16:25 -0000	1.8
  +++ Logger.java	1 Jun 2004 21:42:21 -0000	1.9
  @@ -1 +1 @@
  -package org.apache.ojb.broker.util.logging;

/* Copyright 2002-2004 The Apache Software
Foundation
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may
not use this file except in compliance with the License.
 * You may obtain a copy of the License
at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable
law or agreed to in writing, software
 * distributed under the License is distributed on an
"AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
 * limitations under
the License.
 */

import org.apache.ojb.broker.util.configuration.Configurable;

import java.io.Serializable;


/**
* this interface defines the behaviour of a logging mechanism.
 * This API corresponds closely
to the LOG4J Category Api.
 * By using this interface OJB remains free from Logger-Implementation
* specific code.
 */
public interface Logger extends Serializable, Configurable
{
	static
final long serialVersionUID = 1177329037874407180L;    /*
     * OJB loglevel constants. they
corespond directly to LOG4J LogLevels.
     */
    public final static int DEBUG = 1;
   
public final static int INFO = 2;
    public final static int WARN = 3;
    public final static
int ERROR = 4;
    public final static int FATAL = 5;


    /**
     * generate a message
for loglevel DEBUG
     * @param pObject the message Object
     */
    public void debug(Object
pObject);

    /**
     * generate a message for loglevel INFO
     * @param pObject the message
Object
     */
    public void info(Object pObject);

    /**
     * generate a message for
loglevel WARN
     * @param pObject the message Object
     */
    public void warn(Object
pObject);

    /**
     * generate a message for loglevel ERROR
     * @param pObject the
message Object
     */
    public void error(Object pObject);

    /**
     * generate a message
for loglevel FATAL
     * @param pObject the message Object
     */
    public void fatal(Object
pObject);

    public void debug(Object message, Throwable obj);
    public void info(Object
message, Throwable obj);
    public void warn(Object message, Throwable obj);
    public void
error(Object message, Throwable obj);
    public void fatal(Object message, Throwable obj);

   public boolean isEnabledFor(int priority);
    public boolean isDebugEnabled();

    /**
    * returns the name of the logger isntance
     */
    public String getName();

    /**
    * Exception safe log method.
     * This method can be used to prevent any exception thrown
by obj.toString() implementations.
     * Log level used : DEBUG
     */
    public void safeDebug(String
message, Object obj);

    /**
     * Exception safe log method.
     * This method can be
used to prevent any exception thrown by obj.toString() implementations.
     * Log level used
: DEBUG
     */
    public void safeDebug(String message, Object obj, Throwable t);

    /**
    * Exception safe log method.
     * This method can be used to prevent any exception thrown
by obj.toString() implementations.
     * Log level used : INFO
     */
    public void safeInfo(String
message, Object obj);

    /**
     * Exception safe log method.
     * This method can be
used to prevent any exception thrown by obj.toString() implementations.
     * Log level used
: INFO
     */
    public void safeInfo(String message, Object obj, Throwable t);

    /**
    * Exception safe log method.
     * This method can be used to prevent any exception thrown
by obj.toString() implementations.
     * Log level used : WARN
     */
    public void safeWarn(String
message, Object obj);

    /**
     * Exception safe log method.
     * This method can be
used to prevent any exception thrown by obj.toString() implementations.
     * Log level used
: WARN
     */
    public void safeWarn(String message, Object obj, Throwable t);

    /**
    * Exception safe log method.
     * This method can be used to prevent any exception thrown
by obj.toString() implementations.
     * Log level used : ERROR
     */
    public void safeError(String
message, Object obj);

    /**
     * Exception safe log method.
     * This method can be
used to prevent any exception thrown by obj.toString() implementations.
     * Log level used
: ERROR
     */
    public void safeError(String message, Object obj, Throwable t);

    /**
    * Exception safe log method.
     * This method can be used to prevent any exception thrown
by obj.toString() implementations.
     * Log level used : FATAL
     */
    public void safeFatal(String
message, Object obj);

    /**
     * Exception safe log method.
     * This method can be
used to prevent any exception thrown by obj.toString() implementations.
     * Log level used
: FATAL
     */
    public void safeFatal(String message, Object obj, Throwable t);
}
  +package org.apache.ojb.broker.util.logging;

/* Copyright 2002-2004 The Apache Software
Foundation
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may
not use this file except in compliance with the License.
 * You may obtain a copy of the License
at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable
law or agreed to in writing, software
 * distributed under the License is distributed on an
"AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
 * limitations under
the License.
 */

import org.apache.ojb.broker.util.configuration.Configurable;
import org.apache.ojb.broker.util.configuration.Configuration;
import
org.apache.ojb.broker.util.configuration.ConfigurationException;

import java.io.Serializable;


/**
* this interface defines the behaviour of a logging mechanism.
 * This API corresponds closely
to the LOG4J Category Api.
 * By using this interface OJB remains free from Logger-Implementation
* specific code.
 */
public interface Logger extends Serializable, Configurable
{
	static
final long serialVersionUID = 1177329037874407180L;    /*
     * OJB loglevel constants. they
corespond directly to LOG4J LogLevels.
     */
    public final static int DEBUG = 1;
   
public final static int INFO = 2;
    public final static int WARN = 3;
    public final static
int ERROR = 4;
    public final static int FATAL = 5;


    /**
     * generate a message
for loglevel DEBUG
     * @param pObject the message Object
     */
    public void debug(Object
pObject);

    /**
     * generate a message for loglevel INFO
     * @param pObject the message
Object
     */
    public void info(Object pObject);

    /**
     * generate a message for
loglevel WARN
     * @param pObject the message Object
     */
    public void warn(Object
pObject);

    /**
     * generate a message for loglevel ERROR
     * @param pObject the
message Object
     */
    public void error(Object pObject);

    /**
     * generate a message
for loglevel FATAL
     * @param pObject the message Object
     */
    public void fatal(Object
pObject);

    public void debug(Object message, Throwable obj);
    public void info(Object
message, Throwable obj);
    public void warn(Object message, Throwable obj);
    public void
error(Object message, Throwable obj);
    public void fatal(Object message, Throwable obj);

   public boolean isEnabledFor(int priority);
    public boolean isDebugEnabled();

    /**
    * returns the name of the logger isntance
     */
    public String getName();

    /**
    * Exception safe log method.
     * This method can be used to prevent any exception thrown
by obj.toString() implementations.
     * Log level used : DEBUG
     * @deprecated The normal
logging methods should always be safe with regard to exceptions
     *             that are
thrown while accessing the arguments. 
     */
    public void safeDebug(String message, Object
obj);

    /**
     * Exception safe log method.
     * This method can be used to prevent
any exception thrown by obj.toString() implementations.
     * Log level used : DEBUG
   
 * @deprecated The normal logging methods should always be safe with regard to exceptions
    *             that are thrown while accessing the arguments. 
     */
    public void
safeDebug(String message, Object obj, Throwable t);

    /**
     * Exception safe log method.
    * This method can be used to prevent any exception thrown by obj.toString() implementations.
    * Log level used : INFO
     * @deprecated The normal logging methods should always be
safe with regard to exceptions
     *             that are thrown while accessing the arguments.

     */
    public void safeInfo(String message, Object obj);

    /**
     * Exception safe
log method.
     * This method can be used to prevent any exception thrown by obj.toString()
implementations.
     * Log level used : INFO
     * @deprecated The normal logging methods
should always be safe with regard to exceptions
     *             that are thrown while accessing
the arguments. 
     */
    public void safeInfo(String message, Object obj, Throwable t);

   /**
     * Exception safe log method.
     * This method can be used to prevent any exception
thrown by obj.toString() implementations.
     * Log level used : WARN
     * @deprecated
The normal logging methods should always be safe with regard to exceptions
     *        
    that are thrown while accessing the arguments. 
     */
    public void safeWarn(String
message, Object obj);

    /**
     * Exception safe log method.
     * This method can be
used to prevent any exception thrown by obj.toString() implementations.
     * Log level used
: WARN
     * @deprecated The normal logging methods should always be safe with regard to
exceptions
     *             that are thrown while accessing the arguments. 
     */
   
public void safeWarn(String message, Object obj, Throwable t);

    /**
     * Exception safe
log method.
     * This method can be used to prevent any exception thrown by obj.toString()
implementations.
     * Log level used : ERROR
     * @deprecated The normal logging methods
should always be safe with regard to exceptions
     *             that are thrown while accessing
the arguments. 
     */
    public void safeError(String message, Object obj);

    /**
 
   * Exception safe log method.
     * This method can be used to prevent any exception thrown
by obj.toString() implementations.
     * Log level used : ERROR
     * @deprecated The normal
logging methods should always be safe with regard to exceptions
     *             that are
thrown while accessing the arguments. 
     */
    public void safeError(String message, Object
obj, Throwable t);

    /**
     * Exception safe log method.
     * This method can be used
to prevent any exception thrown by obj.toString() implementations.
     * Log level used :
FATAL
     * @deprecated The normal logging methods should always be safe with regard to exceptions
    *             that are thrown while accessing the arguments. 
     */
    public void
safeFatal(String message, Object obj);

    /**
     * Exception safe log method.
     * This
method can be used to prevent any exception thrown by obj.toString() implementations.
   
 * Log level used : FATAL
     * @deprecated The normal logging methods should always be safe
with regard to exceptions
     *             that are thrown while accessing the arguments.

     */
    public void safeFatal(String message, Object obj, Throwable t);

    /**
   
 * Configure this logging. Note that the config object will be an instance
     * of {@link
LoggingConfiguration}.
     * 
     * @param config The {@link LoggingConfiguration} object
    * @throws ConfigurationException
     */
    void configure(Configuration config) throws
ConfigurationException;
}
  
  
  
  1.5       +186 -7    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.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- LoggingConfiguration.java	4 Apr 2004 23:53:38 -0000	1.4
  +++ LoggingConfiguration.java	1 Jun 2004 21:42:21 -0000	1.5
  @@ -15,17 +15,196 @@
    * limitations under the License.
    */
   
  -import org.apache.ojb.broker.util.configuration.Configuration;
  +import java.io.InputStream;
  +import java.util.Properties;
  +
  +import org.apache.commons.logging.LogFactory;
  +import org.apache.ojb.broker.util.ClassHelper;
  +import org.apache.ojb.broker.util.configuration.impl.ConfigurationAbstractImpl;
   
   /**
  - * @author Thomas Mahler
  + * Provides the configuration for the logging. Note that this is separated from the OJB
  + * configuration.
  + * 
    * @version $Id$
    */
  -public interface LoggingConfiguration extends Configuration
  +public class LoggingConfiguration extends ConfigurationAbstractImpl
   {
  -    public Class getLoggerClass();
  +    /** The property denoting the OJB logger class */
  +    public static final String PROPERTY_OJB_LOGGERCLASS      = "org.apache.ojb.broker.util.logging.Logger.class";
  +    /** The property denoting the config file for the OJB logger class */
  +    public static final String PROPERTY_OJB_LOGGERCONFIGFILE = "org.apache.ojb.broker.util.logging.Logger.configFile";
  +    /** Default filename of the OJB logging properties file */
  +    public static final String OJB_LOGGING_PROPERTIES_FILE = "OJB-logging.properties";
  +
  +    /** The logger class */
  +    private Class  _loggerClass;
  +    /** The config file for the logger */
  +    private String _loggerConfigFile;
  +
  +    /**
  +     * Creates a new logging configuration object which automatically initializes itself.
  +     */
  +    public LoggingConfiguration()
  +    {
  +        load();
  +    }
  +
  +    /* (non-Javadoc)
  +     * @see org.apache.ojb.broker.util.configuration.impl.ConfigurationAbstractImpl#load()
  +     */
  +    protected void load()
  +    {
  +        Logger bootLogger = LoggerFactory.getBootLogger();
  +
  +        // first we check whether the system property
  +        //   org.apache.ojb.broker.util.logging.Logger
  +        // is set (or its alias LoggerClass which is deprecated)
  +        ClassLoader contextLoader   = ClassHelper.getClassLoader();
  +        String      loggerClassName = null;
  +
  +        _loggerClass      = null;
  +        properties        = new Properties();
  +        loggerClassName   = getLoggerClass(System.getProperties());
  +        _loggerConfigFile = getLoggerConfigFile(System.getProperties());
  +
  +        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);
  +
  +            try
  +            {
  +                InputStream ojbLogPropFile = contextLoader.getResourceAsStream(OJB_LOGGING_PROPERTIES_FILE);
  +
  +                bootLogger.debug("Found logging properties file "+OJB_LOGGING_PROPERTIES_FILE);
  +                properties.load(ojbLogPropFile);
  +                loggerClassName   = getLoggerClass(properties);
  +                _loggerConfigFile = getLoggerConfigFile(properties);
  +            }
  +            catch (Exception ex)
  +            {}
  +        }
  +        if (loggerClassName == null)
  +        {
  +            // deprecated: load the OJB.properties file
  +            // this is not good because we have all OJB properties in this config
  +            String ojbPropFile = System.getProperty("OJB.properties", "OJB.properties");
  +
  +            try
  +            {
  +                InputStream ojbLogPropFile = contextLoader.getResourceAsStream(ojbPropFile);
  +
  +                properties.load(ojbLogPropFile);
  +                loggerClassName   = getLoggerClass(properties);
  +                _loggerConfigFile = getLoggerConfigFile(properties);
  +                if (loggerClassName != null)
  +                {
  +                    // deprecation warning will be enabled after 1.0
  +                    //bootLogger.warn("Please use a separate "+OJB_LOGGING_PROPERTIES_FILE+"
file to specify your logging settings");
  +                }
  +            }
  +            catch (Exception ex)
  +            {}
  +        }
  +        if (loggerClassName != null)
  +        {
  +            try
  +            {
  +                _loggerClass = Class.forName(loggerClassName);
  +            }
  +            catch (ClassNotFoundException ex)
  +            {
  +                _loggerClass = PoorMansLoggerImpl.class;
  +                bootLogger.warn("Could not load logger class "+loggerClassName+", defaulting
to "+_loggerClass.getName(), ex);
  +            }
  +        }
  +        else
  +        {
  +            // still no logger configured - lets check whether commons-logging is configured
  +            if (System.getProperty(LogFactory.FACTORY_PROPERTY) != null)
  +            {
  +                // yep, so use commons-logging
  +                _loggerClass = CommonsLoggerImpl.class;
  +            }
  +            else
  +            {
  +                // but perhaps there is a log4j.properties file ?
  +                try
  +                {
  +                    contextLoader.getResourceAsStream("log4j.properties");
  +                    // yep, so use log4j
  +                    _loggerClass      = Log4jLoggerImpl.class;
  +                    _loggerConfigFile = "log4j.properties";
  +                }
  +                catch (Exception ex)
  +                {}
  +                if (_loggerClass == null)
  +                {
  +                    // no, so default to commons-logging
  +                    _loggerClass = CommonsLoggerImpl.class;
  +                }
  +            }
  +        }
  +    }
  +
  +    private String getLoggerClass(Properties props)
  +    {
  +        String loggerClassName = props.getProperty(PROPERTY_OJB_LOGGERCLASS);
  +
  +        if (loggerClassName == null)
  +        {
  +            loggerClassName = props.getProperty("LoggerClass");
  +        }
  +        return loggerClassName;
  +    }
  +
  +    private String getLoggerConfigFile(Properties props)
  +    {
  +        String loggerConfigFile = props.getProperty(PROPERTY_OJB_LOGGERCONFIGFILE);
  +
  +        if (loggerConfigFile == null)
  +        {
  +            loggerConfigFile = props.getProperty("LoggerConfigFile");
  +        }
  +        return loggerConfigFile;
  +    }
  +
  +    public String getLogLevel(String loggerName)
  +    {
  +        /*
  +        arminw:
  +        use ROOT.LogLevel property to define global
  +        default log level
  +        */
  +        return getString(loggerName + ".LogLevel", getString("ROOT.LogLevel", "INFO"));
  +    }
  +
  +    /* (non-Javadoc)
  +     * @see org.apache.ojb.broker.util.configuration.Configuration#setLogger(org.apache.ojb.broker.util.logging.Logger)
  +     */
  +    public void setLogger(Logger loggerInstance)
  +    {
  +        // ignored - only logging via the boot logger
  +    }
   
  -    public String getLogLevel(String loggerName);
  +    /**
  +     * Returns the logger class.
  +     * 
  +     * @return The logger class
  +     */
  +    public Class getLoggerClass()
  +    {
  +        return _loggerClass;
  +    }
   
  -    public String getLoggerConfigFile();
  +    /**
  +     * Returns the name of the config file for the logger.
  +     * 
  +     * @return The config file if it was configured
  +     */
  +    public String getLoggerConfigFile()
  +    {
  +        return _loggerConfigFile;
  +    }
   }
  
  
  
  1.14      +13 -5     db-ojb/src/java/org/apache/ojb/broker/util/configuration/impl/ConfigurationAbstractImpl.java
  
  Index: ConfigurationAbstractImpl.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/util/configuration/impl/ConfigurationAbstractImpl.java,v
  retrieving revision 1.13
  retrieving revision 1.14
  diff -u -r1.13 -r1.14
  --- ConfigurationAbstractImpl.java	4 Apr 2004 23:53:37 -0000	1.13
  +++ ConfigurationAbstractImpl.java	1 Jun 2004 21:42:21 -0000	1.14
  @@ -15,12 +15,14 @@
    * limitations under the License.
    */
   
  +import org.apache.ojb.broker.metadata.MetadataException;
   import org.apache.ojb.broker.util.configuration.Configuration;
   import org.apache.ojb.broker.util.logging.Logger;
   import org.apache.ojb.broker.util.logging.LoggerFactory;
   import org.apache.ojb.broker.util.ClassHelper;
   
   import java.io.File;
  +import java.io.FileNotFoundException;
   import java.io.InputStream;
   import java.net.URL;
   import java.util.Properties;
  @@ -412,7 +414,7 @@
           properties = new Properties();
           try
           {
  -            URL url = Thread.currentThread().getContextClassLoader().getResource(getFilename());
  +            URL url = ClassHelper.getResource(getFilename());
               if (url == null)
               {
                   url = (new File(getFilename())).toURL();
  @@ -423,10 +425,16 @@
               properties.load(strIn);
               strIn.close();
           }
  -        catch (Exception ignore)
  +        catch (FileNotFoundException ex)
           {
  -            logger.error("Cannot get OJB properties file, try to use default settings!");
  -            properties.put("valid", "false");
  +            // [tomdz] Promoted to info status as this is per se not an error
  +            logger.info("Could not load properties file "+getFilename()+". Using default
settings!");
  +            // [tomdz] There seems to be no use of this setting ?
  +            //properties.put("valid", "false");
  +        }
  +        catch (Exception ex)
  +        {
  +            throw new MetadataException("An error happend while loading the properties
file "+getFilename(), ex);
           }
       }
   
  
  
  
  1.35      +14 -37    db-ojb/src/java/org/apache/ojb/broker/util/configuration/impl/OjbConfiguration.java
  
  Index: OjbConfiguration.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/util/configuration/impl/OjbConfiguration.java,v
  retrieving revision 1.34
  retrieving revision 1.35
  diff -u -r1.34 -r1.35
  --- OjbConfiguration.java	9 Apr 2004 13:22:29 -0000	1.34
  +++ OjbConfiguration.java	1 Jun 2004 21:42:21 -0000	1.35
  @@ -33,9 +33,6 @@
   import org.apache.ojb.broker.core.proxy.ProxyConfiguration;
   import org.apache.ojb.broker.core.proxy.IndirectionHandlerDefaultImpl;
   import org.apache.ojb.broker.core.proxy.SetProxyDefaultImpl;
  -import org.apache.ojb.broker.util.logging.Logger;
  -import org.apache.ojb.broker.util.logging.LoggingConfiguration;
  -import org.apache.ojb.broker.util.logging.PoorMansLoggerImpl;
   import org.apache.ojb.broker.util.pooling.PoolConfiguration;
   import org.apache.ojb.odmg.OdmgConfiguration;
   import org.apache.ojb.odmg.collections.DListImpl;
  @@ -56,22 +53,24 @@
    * @version $Id$
    */
   public class OjbConfiguration extends    ConfigurationAbstractImpl
  -                              implements LoggingConfiguration,
  -                                         OdmgConfiguration,
  +                              implements OdmgConfiguration,
                                            LockingConfiguration,
                                            PersistenceBrokerConfiguration,
                                            ProxyConfiguration,
                                            PBPoolConfiguration,
                                            MetadataConfiguration
   {
  +    /** Default filename of the OJB properties file */
  +    public static final String OJB_PROPERTIES_FILE = "OJB.properties";
  +    /** Default filename of the OJB repository metadata file */
  +    public static final String OJB_METADATA_FILE   = "repository.xml";
  +
       /** the repository file keeping the O/R Metadata*/
       private String repositoryFilename;
       private Class objectCacheClass;
       private String[] objectCacheFilter;
       private Class connectionFactoryClass;
  -    private Class loggerClass;
       private Class persistentFieldClass;
  -    private String loggerConfigFile;
       private Class persistenceBrokerClass;
   
       // proxy related classes
  @@ -123,21 +122,6 @@
           return repositoryFilename;
       }
   
  -    public String getLoggerConfigFile()
  -    {
  -        return loggerConfigFile;
  -    }
  -
  -    public String getLogLevel(String loggerName)
  -    {
  -        /*
  -        arminw:
  -        use ROOT.LogLevel property to define global
  -        default log level
  -        */
  -        return this.getString(loggerName + ".LogLevel", getString("ROOT.LogLevel", "INFO"));
  -    }
  -
       //*************************************************************
       //PBPoolConfiguration methods
       public int getMaxActive()
  @@ -217,11 +201,6 @@
           return lockMapClass;
       }
   
  -    public Class getLoggerClass()
  -    {
  -        return loggerClass;
  -    }
  -
       public Class getPersistentFieldClass()
       {
           return persistentFieldClass;
  @@ -277,21 +256,23 @@
       }
   
       /**
  -     * loads the configuration from file "OBJ.properties". If the system
  +     * Loads the configuration from file "OBJ.properties". If the system
        * property "OJB.properties" is set, then the configuration in that file is
  -     * loaded.
  +     * loaded. Otherwise, the file "OJB.properties" is tried. If that is also
  +     * unsuccessful, then the configuration is filled with default values.
        */
       protected void load()
       {
           // properties file may be set as a System property.
           // if no property is set take default name.
  -        String fn = System.getProperty("OJB.properties", "OJB.properties");
  +        String fn = System.getProperty(OJB_PROPERTIES_FILE, OJB_PROPERTIES_FILE);
           setFilename(fn);
           super.load();
   
  -        repositoryFilename = getString("repositoryFile", "repository.xml");
  +        // default repository & connection descriptor file
  +        repositoryFilename = getString("repositoryFile", OJB_METADATA_FILE);
   
  -        // load ObjectCache Class
  +        // object cache class
           objectCacheClass = getClass("ObjectCacheClass", ObjectCacheDefaultImpl.class, ObjectCache.class);
           // load ObjectCache filters
           objectCacheFilter = getStrings("ObjectCacheFilter", "", ",");
  @@ -305,10 +286,6 @@
   
           // load LockMap Class
           lockMapClass = getClass("LockMapClass", InMemoryLockMapImpl.class, LockMap.class);
  -
  -        // load Logger Class
  -        loggerClass = getClass("LoggerClass", PoorMansLoggerImpl.class, Logger.class);
  -        loggerConfigFile = getString("LoggerConfigFile", "");
   
           // load PersistentField Class
           persistentFieldClass =
  
  
  
  1.69      +2 -66     db-ojb/src/test/org/apache/ojb/OJB.properties
  
  Index: OJB.properties
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/test/org/apache/ojb/OJB.properties,v
  retrieving revision 1.68
  retrieving revision 1.69
  diff -u -r1.68 -r1.69
  --- OJB.properties	20 May 2004 11:13:10 -0000	1.68
  +++ OJB.properties	1 Jun 2004 21:42:21 -0000	1.69
  @@ -430,72 +430,8 @@
   #
   #
   #----------------------------------------------------------------------------------------
  -# Logging
  +# Logging settings are now in their own file, OJB-logging.properties
   #----------------------------------------------------------------------------------------
  -# The LoggerClass entry tells OJB which concrete Logger
  -# implementation is to be used.
  -#
  -# Commons-logging
  -#LoggerClass=org.apache.ojb.broker.util.logging.CommonsLoggerImpl
  -# log4j based logging
  -#LoggerClass=org.apache.ojb.broker.util.logging.Log4jLoggerImpl
  -# OJB's own simple looging support
  -LoggerClass=org.apache.ojb.broker.util.logging.PoorMansLoggerImpl
  -LoggerConfigFile=log4j.properties
  -#
  -# The LogLevel entries tells OJB which LogLevels are active
  -# for the different loggers used within OJB
  -# Loglevels: DEBUG < INFO < WARN < ERROR < FATAL
  -# That is loglevel WARN won't log DEBUG and INFO messages,
  -# but will log WARN, ERROR, and FATAL messages
  -#
  -# Global default log level used for all logging
  -# entities if not specified
  -ROOT.LogLevel=ERROR
  -#
  -# The Default Logger instance used within OJB
  -DEFAULT.LogLevel=WARN
  -# Logger for PersistenceBrokerImpl class
  -org.apache.ojb.broker.core.PersistenceBrokerImpl.LogLevel=WARN
  -# Logger for PersistenceBrokerFactory class PersistenceBrokerFactoryDefaultImpl
  -org.apache.ojb.broker.core.PersistenceBrokerFactoryDefaultImpl.LogLevel=WARN
  -# Logger for RepositoryXmlHandler, useful for debugging parsing of repository.xml!
  -# persistence capable object metadata
  -org.apache.ojb.broker.metadata.RepositoryXmlHandler.LogLevel=WARN
  -# Logger for ConnectionDescriptorXmlHandler, useful for debugging parsing of repository.xml!
  -# connection specific metadata
  -org.apache.ojb.broker.metadata.ConnectionDescriptorXmlHandler.LogLevel=WARN
  -# Logger for JdbcAccess, useful for debugging JDBC related problems
  -org.apache.ojb.broker.accesslayer.JdbcAccessImpl.LogLevel=WARN
  -# Logger for RsIterator, useful for debugging problems with Object materialization
  -org.apache.ojb.broker.accesslayer.RsIterator.LogLevel=WARN
  -# Logger for StatementsForClass, useful for debugging JDBC Connection related problems
  -org.apache.ojb.broker.accesslayer.StatementsForClassImpl.LogLevel=WARN
  -# Logger for SqlGenerator, useful for debugging generation of SQL
  -org.apache.ojb.broker.accesslayer.sql.SqlGeneratorDefaultImpl.LogLevel=WARN
  -# Logger for RepositoryPersistor
  -org.apache.ojb.broker.metadata.RepositoryPersistor.LogLevel=WARN
  -# Logger for ConnectionFactory base class
  -org.apache.ojb.broker.accesslayer.ConnectionFactoryAbstractImpl.LogLevel=WARN
  -# Logger for ConnectionManager
  -org.apache.ojb.broker.accesslayer.ConnectionManagerImpl.LogLevel=WARN
  -# Logger for IndirectionHandler class
  -org.apache.ojb.broker.core.proxy.IndirectionHandler.LogLevel=WARN
  -#
  -# Special Logger categories used in test suite and tutorials
  -#
  -# Logger for the ODMG Implementation
  -ODMG.LogLevel=DEBUG
  -# Logger for the JDO RI Implementation
  -JDO.LogLevel=DEBUG
  -# Logger for the performance tests
  -performance.LogLevel=INFO
  -# Logger for the soda api
  -soda.LogLevel=WARN
  -# Logger for the factory service
  -ConfigurableFactory.LogLevel=WARN
  -#
  -#
   #----------------------------------------------------------------------------------------
   # End of OJB.properties file
   #----------------------------------------------------------------------------------------
  
  
  
  1.1                  db-ojb/src/test/org/apache/ojb/OJB-logging.properties
  
  Index: OJB-logging.properties
  ===================================================================
  #<!--
  #/* Copyright 2002-2004 The Apache Software Foundation
  # *
  # * Licensed under the Apache License, Version 2.0 (the "License");
  # * you may not use this file except in compliance with the License.
  # * You may obtain a copy of the License at
  # *
  # *     http://www.apache.org/licenses/LICENSE-2.0
  # *
  # * Unless required by applicable law or agreed to in writing, software
  # * distributed under the License is distributed on an "AS IS" BASIS,
  # * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  # * See the License for the specific language governing permissions and
  # * limitations under the License.
  # */
  #-->
  # OJB-logging.properties -- configuration of the logging within the OJB runtime environment
  # Version: 1.0
  # (c) 2001, 2002, 2003 Apache Software Foundation
  # Author: Thomas Mahler and many others
  # @version $Id: OJB-logging.properties,v 1.1 2004/06/01 21:42:21 tomdz Exp $
  #----------------------------------------------------------------------------------------
  # The LoggerClass entry tells OJB which concrete Logger implementation is to be used.
  # If it is not specified (or this file is not present/found, then OJB will check
  # whether there is a log4j.properties or commons-logging.properties file, in which
  # case it will use Log4J/commons-logging. If neither is present, then OJB will default
  # to commons-logging.
  #
  # Commons-logging
  #LoggerClass=org.apache.ojb.broker.util.logging.CommonsLoggerImpl
  # log4j based logging
  #LoggerClass=org.apache.ojb.broker.util.logging.Log4jLoggerImpl
  # OJB's own simple looging support
  LoggerClass=org.apache.ojb.broker.util.logging.PoorMansLoggerImpl
  LoggerConfigFile=log4j.properties
  #
  # The LogLevel entries tells OJB which LogLevels are active
  # for the different loggers used within OJB
  # Loglevels: DEBUG < INFO < WARN < ERROR < FATAL
  # That is loglevel WARN won't log DEBUG and INFO messages,
  # but will log WARN, ERROR, and FATAL messages
  #
  # Global default log level used for all logging
  # entities if not specified
  ROOT.LogLevel=ERROR
  #
  # The Default Logger instance used within OJB
  DEFAULT.LogLevel=WARN
  # Logger for PersistenceBrokerImpl class
  org.apache.ojb.broker.core.PersistenceBrokerImpl.LogLevel=WARN
  # Logger for PersistenceBrokerFactory class PersistenceBrokerFactoryDefaultImpl
  org.apache.ojb.broker.core.PersistenceBrokerFactoryDefaultImpl.LogLevel=WARN
  # Logger for RepositoryXmlHandler, useful for debugging parsing of repository.xml!
  # persistence capable object metadata
  org.apache.ojb.broker.metadata.RepositoryXmlHandler.LogLevel=WARN
  # Logger for ConnectionDescriptorXmlHandler, useful for debugging parsing of repository.xml!
  # connection specific metadata
  org.apache.ojb.broker.metadata.ConnectionDescriptorXmlHandler.LogLevel=WARN
  # Logger for JdbcAccess, useful for debugging JDBC related problems
  org.apache.ojb.broker.accesslayer.JdbcAccessImpl.LogLevel=WARN
  # Logger for RsIterator, useful for debugging problems with Object materialization
  org.apache.ojb.broker.accesslayer.RsIterator.LogLevel=WARN
  # Logger for StatementsForClass, useful for debugging JDBC Connection related problems
  org.apache.ojb.broker.accesslayer.StatementsForClassImpl.LogLevel=WARN
  # Logger for SqlGenerator, useful for debugging generation of SQL
  org.apache.ojb.broker.accesslayer.sql.SqlGeneratorDefaultImpl.LogLevel=WARN
  # Logger for RepositoryPersistor
  org.apache.ojb.broker.metadata.RepositoryPersistor.LogLevel=WARN
  # Logger for ConnectionFactory base class
  org.apache.ojb.broker.accesslayer.ConnectionFactoryAbstractImpl.LogLevel=WARN
  # Logger for ConnectionManager
  org.apache.ojb.broker.accesslayer.ConnectionManagerImpl.LogLevel=WARN
  # Logger for IndirectionHandler class
  org.apache.ojb.broker.core.proxy.IndirectionHandler.LogLevel=WARN
  #
  # Special Logger categories used in test suite and tutorials
  #
  # Logger for the ODMG Implementation
  ODMG.LogLevel=DEBUG
  # Logger for the JDO RI Implementation
  JDO.LogLevel=DEBUG
  # Logger for the performance tests
  performance.LogLevel=INFO
  # Logger for the soda api
  soda.LogLevel=WARN
  # Logger for the factory service
  ConfigurableFactory.LogLevel=WARN
  #
  #
  #----------------------------------------------------------------------------------------
  # End of OJB.properties file
  #----------------------------------------------------------------------------------------
  
  
  

---------------------------------------------------------------------
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