db-ojb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From b..@apache.org
Subject cvs commit: db-ojb/src/java/org/apache/ojb/broker/util/logging LoggerFactoryImpl.java Log4jLoggerImpl.java
Date Sat, 06 Dec 2003 13:10:39 GMT
brj         2003/12/06 05:10:39

  Modified:    src/java/org/apache/ojb/broker/util/logging
                        LoggerFactoryImpl.java Log4jLoggerImpl.java
  Log:
  fixed log4j dependency (patch by Michael Becke)
  
  Revision  Changes    Path
  1.12      +5 -83     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.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- LoggerFactoryImpl.java	6 Mar 2003 14:41:46 -0000	1.11
  +++ LoggerFactoryImpl.java	6 Dec 2003 13:10:39 -0000	1.12
  @@ -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
  -        }
       }
   
   }
  
  
  
  1.12      +79 -4     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.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- Log4jLoggerImpl.java	13 Mar 2003 19:56:33 -0000	1.11
  +++ Log4jLoggerImpl.java	6 Dec 2003 13:10:39 -0000	1.12
  @@ -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());
  +        }
   	}
   
   }
  
  
  

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