db-ojb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jakob Braeuchi <jbraeu...@gmx.ch>
Subject Re: [OJB] Issue #OJB220 - Log4j jar is required at runtime even if not used.
Date Fri, 05 Dec 2003 20:02:30 GMT
hi michael,

eclipse does not like patches affecting multiple files. please post a 
patch for each file.

thanks
jakob

Michael Becke wrote:

> I can't figure out how to attach a patch to an existing issue in Scarab, 
> so here it is instead.  This patch just moves all of the Log4j code into 
>  Log4jLoggerImpl.
> 
> Thanks,
> 
> Mike
> 
> 
> 
> Michael Becke wrote:
> 
>> You can view the issue detail at the following URL:
>>
>>     http://nagoya.apache.org/scarab/issues/id/OJB220
>>
>> Type
>>  Patch
>>
>> Issue ID
>>  OJB220 (Log4j jar is required at runtime even if not used.)
>>
>> Reported by
>>  Michael Becke
>>  becke@u.washington.edu (becke@u.washington.edu)
>>
>> New issue details:
>> ---------------------------------------------------------
>>
>> Summary set to "Log4j jar is required at runti..."
>> Description set to "LoggerFactoryImpl requires Log..."
>> Operating system set to "All"
>> Issue created
>> Platform set to "All"
>>
>> ---------------------------------------------------------
>> This message is automatically generated by the Scarab
>> issue tracking system.  For more information:
>> http://scarab.tigris.org/
>>
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: ojb-dev-unsubscribe@db.apache.org
>> For additional commands, e-mail: ojb-dev-help@db.apache.org
>>
> 
> ------------------------------------------------------------------------
> 
> Index: Log4jLoggerImpl.java
> ===================================================================
> RCS file: /home/cvspublic/db-ojb/src/java/org/apache/ojb/broker/util/logging/Log4jLoggerImpl.java,v
> retrieving revision 1.11
> diff -u -r1.11 Log4jLoggerImpl.java
> --- Log4jLoggerImpl.java	13 Mar 2003 19:56:33 -0000	1.11
> +++ Log4jLoggerImpl.java	5 Dec 2003 19:12:03 -0000
> @@ -54,9 +54,13 @@
>   * <http://www.apache.org/>.
>   */
>  
> +import java.net.URL;
> +import java.util.Enumeration;
>  import java.util.HashMap;
>  
> +import org.apache.log4j.LogManager;
>  import org.apache.log4j.Priority;
> +import org.apache.log4j.PropertyConfigurator;
>  import org.apache.ojb.broker.util.configuration.Configuration;
>  import org.apache.ojb.broker.util.configuration.ConfigurationException;
>  
> @@ -85,6 +89,9 @@
>  
>  	static private final String FQCN = Log4jLoggerImpl.class.getName();
>  
> +    /** flag about log4j configuration state */
> +    private static boolean log4jConfigured = false;
> +
>  	static {
>  		priorityMap = new HashMap();
>  		priorityMap.put(new Integer(Logger.DEBUG), Priority.DEBUG);
> @@ -94,6 +101,72 @@
>  		priorityMap.put(new Integer(Logger.FATAL), Priority.FATAL);
>  	}
>  
> +    /**
> +     * Helper method to check if log4j is already configured
> +     */
> +    private static synchronized boolean isLog4JConfigured()
> +    {
> +        if (log4jConfigured)
> +            return true;
> +
> +        Enumeration enum = org.apache.log4j.Logger.getRootLogger().getAllAppenders();
> +
> +        if (!(enum instanceof org.apache.log4j.helpers.NullEnumeration))
> +        {
> +            log4jConfigured = true;
> +            return true;
> +        }
> +        else
> +        {
> +            Enumeration cats = LogManager.getCurrentLoggers();
> +            while (cats.hasMoreElements())
> +            {
> +                org.apache.log4j.Logger c = (org.apache.log4j.Logger) cats.nextElement();
> +                if (!(c.getAllAppenders() instanceof org.apache.log4j.helpers.NullEnumeration))
> +                {
> +                    log4jConfigured = true;
> +                    return true;
> +                }
> +            }
> +        }
> +        return false;
> +    }
> +
> +    /**
> +     * Initialization of log4j <br>
> +     * <b>NOTE</b>  - if log4j property file is called log4j.properties
then
> +     * log4j will be configured already.
> +     *
> +     */
> +    private static synchronized void initializeLog4JSubSystem(String configFile)
> +    {
> +        LoggerFactory.getBootLogger().info("Initializing Log4J using file:" + configFile);
> +        if (configFile != null)
> +        {
> +            // try resource look in classpath
> +            URL url = Thread.currentThread().getContextClassLoader().getResource(configFile);
> +            LoggerFactory.getBootLogger().info("Initializing Log4J : resource from config
file:" + url);
> +            if (url != null)
> +            {
> +                PropertyConfigurator.configure(url);
> +            }
> +
> +            // if file is not in classpath try ordinary filesystem lookup
> +            else if (configFile != "")
> +            {
> +                PropertyConfigurator.configure(configFile);
> +            }
> +            else
> +            {
> +                // no configuration available
> +            }
> +        }
> +        else
> +        {
> +            // no configuration available
> +        }
> +    }
> +
>  	public Log4jLoggerImpl(String name)
>  	{
>  		this.name = name;
> @@ -386,13 +459,15 @@
>  	}
>  
>  	/**
> -	 * This impl just throws UnsupporteOperationException because Log4j logger have a centrilized
configuration/initialization system
> -	 *
>  	 * @see org.apache.ojb.broker.util.configuration.Configurable#configure(Configuration)
>  	 */
>  	public void configure(Configuration config) throws ConfigurationException
>  	{
> -		throw new UnsupportedOperationException("Log4j loggers can't be individually initialized
!");
> +        if (!isLog4JConfigured())
> +        {
> +            LoggingConfiguration lc = (LoggingConfiguration) config;
> +            initializeLog4JSubSystem(lc.getLoggerConfigFile());
> +        }
>  	}
>  
>  }
> Index: LoggerFactoryImpl.java
> ===================================================================
> RCS file: /home/cvspublic/db-ojb/src/java/org/apache/ojb/broker/util/logging/LoggerFactoryImpl.java,v
> retrieving revision 1.11
> diff -u -r1.11 LoggerFactoryImpl.java
> --- LoggerFactoryImpl.java	6 Mar 2003 14:41:46 -0000	1.11
> +++ LoggerFactoryImpl.java	5 Dec 2003 19:12:04 -0000
> @@ -56,17 +56,13 @@
>  
>  //OJB
>  
> -import org.apache.log4j.LogManager;
> -import org.apache.log4j.PropertyConfigurator;
> +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;
>  
> -import java.net.URL;
> -import java.util.Enumeration;
> -import java.util.HashMap;
> -import java.util.Map;
> -
>  /**
>   * The factory class <code>LoggerFactory</code> can be used
>   * to create <code>Logger</code> instances.
> @@ -92,9 +88,6 @@
>      /** Used for caching logger instances */
>      Map cache = new HashMap();
>  
> -    /** flag about log4j configuration state */
> -    private boolean log4jConfigured = false;
> -
>      // yes. it's a singleton !
>      private LoggerFactoryImpl()
>      {
> @@ -187,10 +180,7 @@
>              if (logger instanceof Log4jLoggerImpl)
>              {
>                  getBootLogger().debug("Initializing Log4j logger instance " + loggerName);
> -                if (!isLog4JConfigured())
> -                {
> -                    initializeLog4JSubSystem(lc.getLoggerConfigFile());
> -                }
> +                logger.configure(lc);
>              }
>              else if (logger instanceof PoorMansLoggerImpl)
>              {
> @@ -226,74 +216,6 @@
>              logger.error("[" + this.getClass().getName() + "]   Could not set logger
for class " + loggerClass, t);
>          }
>          return logger;
> -    }
> -
> -
> -    /**
> -     * Helper method to check if log4j is already configured
> -     */
> -    synchronized boolean isLog4JConfigured()
> -    {
> -        if (log4jConfigured)
> -            return true;
> -
> -        Enumeration enum = org.apache.log4j.Logger.getRootLogger().getAllAppenders();
> -
> -        if (!(enum instanceof org.apache.log4j.helpers.NullEnumeration))
> -        {
> -            log4jConfigured = true;
> -            return true;
> -        }
> -        else
> -        {
> -            Enumeration cats = LogManager.getCurrentLoggers();
> -            while (cats.hasMoreElements())
> -            {
> -                org.apache.log4j.Logger c = (org.apache.log4j.Logger) cats.nextElement();
> -                if (!(c.getAllAppenders() instanceof org.apache.log4j.helpers.NullEnumeration))
> -                {
> -                    log4jConfigured = true;
> -                    return true;
> -                }
> -            }
> -        }
> -        return false;
> -    }
> -
> -
> -    /**
> -     * Initialization of log4j <br>
> -     * <b>NOTE</b>  - if log4j property file is called log4j.properties
then
> -     * log4j will be configured already.
> -     *
> -     */
> -    synchronized void initializeLog4JSubSystem(String configFile)
> -    {
> -        getBootLogger().info("Initializing Log4J using file:" + configFile);
> -        if (configFile != null)
> -        {
> -            // try resource look in classpath
> -            URL url = Thread.currentThread().getContextClassLoader().getResource(configFile);
> -            getBootLogger().info("Initializing Log4J : resource from config file:" +
url);
> -            if (url != null)
> -            {
> -                PropertyConfigurator.configure(url);
> -            }
> -
> -            // if file is not in classpath try ordinary filesystem lookup
> -            else if (configFile != "")
> -            {
> -                PropertyConfigurator.configure(configFile);
> -            }
> -            else
> -            {
> -                // no configuration available
> -            }
> -        }
> -        else
> -        {
> -            // no configuration available
> -        }
>      }
>  
>  }
> 
> 
> 
> ------------------------------------------------------------------------
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: ojb-dev-unsubscribe@db.apache.org
> For additional commands, e-mail: ojb-dev-help@db.apache.org


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