arminw      2005/09/03 11:07:59

  Modified:    src/java/org/apache/ojb/broker/util/logging
                        CommonsLoggerImpl.java Log4jLoggerImpl.java
                        PoorMansLoggerImpl.java
  Log:
  merge with 1.0.x, fix bug in CommonLoggerImpl, improvements
  
  Revision  Changes    Path
  1.6       +35 -18    
db-ojb/src/java/org/apache/ojb/broker/util/logging/CommonsLoggerImpl.java
  
  Index: CommonsLoggerImpl.java
  ===================================================================
  RCS file: 
/home/cvs/db-ojb/src/java/org/apache/ojb/broker/util/logging/CommonsLoggerImpl.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- CommonsLoggerImpl.java    14 Nov 2004 09:36:43 -0000      1.5
  +++ CommonsLoggerImpl.java    3 Sep 2005 18:07:59 -0000       1.6
  @@ -43,6 +43,40 @@
        }
   
        /**
  +      * Returns the log.
  +      * @return Log
  +      */
  +     public Log getLog()
  +     {
  +             /*
  +             arminw: Log is declared 'transient', thus we have to null-check
  +             this field
  +             */
  +        if(log == null)
  +        {
  +            log = LogFactory.getLog(name);
  +        }
  +        return log;
  +     }
  +
  +    /**
  +      * @see org.apache.ojb.broker.util.logging.Logger#isEnabledFor(int)
  +      */
  +     public boolean isEnabledFor(int priority)
  +     {
  +             Log commonsLog = getLog();
  +        switch(priority)
  +        {
  +            case Logger.DEBUG: return commonsLog.isDebugEnabled();
  +            case Logger.INFO: return commonsLog.isInfoEnabled();
  +            case Logger.WARN: return commonsLog.isWarnEnabled();
  +            case Logger.ERROR: return commonsLog.isErrorEnabled();
  +            case Logger.FATAL: return commonsLog.isFatalEnabled();
  +        }
  +        return false;
  +    }
  +
  +    /**
         * @see org.apache.ojb.broker.util.logging.Logger#debug(Object)
         */
        public void debug(Object pObject)
  @@ -123,14 +157,6 @@
        }
   
        /**
  -      * @see org.apache.ojb.broker.util.logging.Logger#isEnabledFor(int)
  -      */
  -     public boolean isEnabledFor(int priority)
  -     {
  -             return false;
  -     }
  -
  -     /**
         * @see org.apache.ojb.broker.util.logging.Logger#isDebugEnabled()
         */
        public boolean isDebugEnabled()
  @@ -286,13 +312,4 @@
                return toString;
        }
   
  -     /**
  -      * Returns the log.
  -      * @return Log
  -      */
  -     public Log getLog()
  -     {
  -             return log;
  -     }
  -
   }
  
  
  
  1.19      +26 -34    
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.18
  retrieving revision 1.19
  diff -u -r1.18 -r1.19
  --- Log4jLoggerImpl.java      14 Nov 2004 09:36:43 -0000      1.18
  +++ Log4jLoggerImpl.java      3 Sep 2005 18:07:59 -0000       1.19
  @@ -17,7 +17,6 @@
   
   import java.net.URL;
   import java.util.Enumeration;
  -import java.util.HashMap;
   
   import org.apache.log4j.LogManager;
   import org.apache.log4j.Level;
  @@ -43,23 +42,12 @@
    */
   public class Log4jLoggerImpl implements Logger
   {
  -     static private HashMap priorityMap;
  -     private transient org.apache.log4j.Logger logger;
  -     private String name;
  -
        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), Level.DEBUG);
  -             priorityMap.put(new Integer(Logger.INFO), Level.INFO);
  -             priorityMap.put(new Integer(Logger.WARN), Level.WARN);
  -             priorityMap.put(new Integer(Logger.ERROR), Level.ERROR);
  -             priorityMap.put(new Integer(Logger.FATAL), Level.FATAL);
  -     }
  +    private transient org.apache.log4j.Logger logger;
  +     private String name;
   
       /**
        * Helper method to check if log4j is already configured
  @@ -101,7 +89,11 @@
       private static synchronized void initializeLog4JSubSystem(String 
configFile)
       {
           LoggerFactory.getBootLogger().info("Initializing Log4J using file:" 
+ configFile);
  -        if (configFile != null)
  +        if(configFile == null || "".equals(configFile.trim()))
  +        {
  +            // no configuration available
  +        }
  +        else
           {
               // try resource look in classpath
               URL url = ClassHelper.getResource(configFile);
  @@ -110,22 +102,13 @@
               {
                   PropertyConfigurator.configure(url);
               }
  -
               // if file is not in classpath try ordinary filesystem lookup
  -            else if (configFile != "")
  +            else
               {
                   PropertyConfigurator.configure(configFile);
               }
  -            else
  -            {
  -                // no configuration available
               }
           }
  -        else
  -        {
  -            // no configuration available
  -        }
  -    }
   
        public Log4jLoggerImpl(String name, LoggingConfiguration conf)
        {
  @@ -314,7 +297,7 @@
        {
                if (Level.WARN.isGreaterOrEqual(getLevel()))
                {
  -                     String toString = null;
  +                     String toString;
                        try
                        {
                                toString = obj.toString();
  @@ -331,7 +314,7 @@
        {
                if (Level.WARN.isGreaterOrEqual(getLevel()))
                {
  -                     String toString = null;
  +                     String toString;
                        try
                        {
                                toString = obj.toString();
  @@ -348,7 +331,7 @@
        {
                if (Level.ERROR.isGreaterOrEqual(getLevel()))
                {
  -                     String toString = null;
  +                     String toString;
                        try
                        {
                                toString = obj.toString();
  @@ -365,7 +348,7 @@
        {
                if (Level.ERROR.isGreaterOrEqual(getLevel()))
                {
  -                     String toString = null;
  +                     String toString;
                        try
                        {
                                toString = obj.toString();
  @@ -382,7 +365,7 @@
        {
                if (Level.FATAL.isGreaterOrEqual(getLevel()))
                {
  -                     String toString = null;
  +                     String toString;
                        try
                        {
                                toString = obj.toString();
  @@ -399,7 +382,7 @@
        {
                if (Level.FATAL.isGreaterOrEqual(getLevel()))
                {
  -                     String toString = null;
  +                     String toString;
                        try
                        {
                                toString = obj.toString();
  @@ -419,6 +402,15 @@
   
        public boolean isEnabledFor(int priority)
        {
  -             return getLogger().isEnabledFor((Level) priorityMap.get(new 
Integer(priority)));
  -     }
  +        org.apache.log4j.Logger log4j = getLogger();
  +        switch(priority)
  +        {
  +            case Logger.DEBUG: return log4j.isDebugEnabled();
  +            case Logger.INFO: return log4j.isInfoEnabled();
  +            case Logger.WARN: return 
log4j.isEnabledFor(org.apache.log4j.Priority.WARN);
  +            case Logger.ERROR: return 
log4j.isEnabledFor(org.apache.log4j.Priority.ERROR);
  +            case Logger.FATAL: return 
log4j.isEnabledFor(org.apache.log4j.Priority.FATAL);
  +         }
  +        return false;
  +    }
   }
  
  
  
  1.13      +32 -19    
db-ojb/src/java/org/apache/ojb/broker/util/logging/PoorMansLoggerImpl.java
  
  Index: PoorMansLoggerImpl.java
  ===================================================================
  RCS file: 
/home/cvs/db-ojb/src/java/org/apache/ojb/broker/util/logging/PoorMansLoggerImpl.java,v
  retrieving revision 1.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- PoorMansLoggerImpl.java   14 Nov 2004 09:36:43 -0000      1.12
  +++ PoorMansLoggerImpl.java   3 Sep 2005 18:07:59 -0000       1.13
  @@ -24,6 +24,20 @@
    */
   public class PoorMansLoggerImpl implements Logger
   {
  +    private static final String STR_DEBUG = "DEBUG";
  +    private static final String STR_INFO = "INFO";
  +    private static final String STR_WARN = "WARN";
  +    private static final String STR_ERROR = "ERROR";
  +    private static final String STR_FATAL = "FATAL";
  +
  +    private static final String STR_DEBUG_MSG = "DEBUG: ";
  +    private static final String STR_INFO_MSG = "INFO: ";
  +    private static final String STR_WARN_MSG = "WARN: ";
  +    private static final String STR_ERROR_MSG = "ERROR: ";
  +    private static final String STR_FATAL_MSG = "FATAL: ";
  +
  +    private static final String BRAKE_OPEN = "[";
  +    private static final String BRAKE_CLOSE = "] ";
   
       private String name;
   
  @@ -66,7 +80,7 @@
       {
           if (DEBUG >= getLevel())
           {
  -            log("DEBUG: ", message, t);
  +            log(STR_DEBUG_MSG, message, t);
           }
       }
   
  @@ -91,7 +105,7 @@
                       toString = "BAD toString() impl for 
"+obj.getClass().getName();
                   }
               }
  -            log("DEBUG: ",message + " : " + toString,t);
  +            log(STR_DEBUG_MSG,message + " : " + toString,t);
           }
       }
   
  @@ -109,7 +123,7 @@
       {
           if (INFO >= getLevel())
           {
  -            log("INFO: ", message, t);
  +            log(STR_INFO_MSG, message, t);
           }
       }
   
  @@ -134,7 +148,7 @@
                       toString = "BAD toString() impl for 
"+obj.getClass().getName();
                   }
               }
  -            log("INFO: ",message + " : " + toString,t);
  +            log(STR_INFO_MSG, message + " : " + toString,t);
           }
       }
   
  @@ -151,7 +165,7 @@
       {
           if (WARN >= getLevel())
           {
  -            log("WARN: ", message, t);
  +            log(STR_WARN_MSG, message, t);
           }
       }
   
  @@ -176,7 +190,7 @@
                       toString = "BAD toString() impl for 
"+obj.getClass().getName();
                   }
               }
  -            log("WARN: ",message + " : " + toString,t);
  +            log(STR_WARN_MSG,message + " : " + toString,t);
           }
       }
   
  @@ -193,7 +207,7 @@
       {
           if (ERROR >= getLevel())
           {
  -            log("ERROR: ", message, t);
  +            log(STR_ERROR_MSG, message, t);
           }
       }
   
  @@ -218,7 +232,7 @@
                       toString = "BAD toString() impl for 
"+obj.getClass().getName();
                   }
               }
  -            log("ERROR: ",message + " : " + toString,t);
  +            log(STR_ERROR_MSG,message + " : " + toString,t);
           }
       }
   
  @@ -235,7 +249,7 @@
       {
           if (FATAL >= getLevel())
           {
  -            log("FATAL: ", message, t);
  +            log(STR_FATAL_MSG, message, t);
           }
       }
   
  @@ -260,7 +274,7 @@
                       toString = "BAD toString() impl for 
"+obj.getClass().getName();
                   }
               }
  -            log("FATAL: ",message + " : " + toString,t);
  +            log(STR_FATAL_MSG,message + " : " + toString,t);
           }
       }
   
  @@ -272,13 +286,12 @@
   
       public boolean isEnabledFor(int priority)
       {
  -        if(priority >= getLevel()) return true;
  -        else return false;
  +        return priority >= getLevel();
       }
   
       protected void log(String aLevel, Object obj, Throwable t)
       {
  -        System.out.print("[" + name + "] " + aLevel);
  +        System.out.print(BRAKE_OPEN + name + BRAKE_CLOSE + aLevel);
           if (obj != null && obj instanceof Throwable)
           {
               try
  @@ -312,23 +325,23 @@
   
        public void setLevel(String levelName)
        {
  -             if (levelName.equalsIgnoreCase("DEBUG"))
  +             if (levelName.equalsIgnoreCase(STR_DEBUG))
                {
                    level = DEBUG;
                }
  -             else if (levelName.equalsIgnoreCase("INFO"))
  +             else if (levelName.equalsIgnoreCase(STR_INFO))
                {
                    level = INFO;
                }
  -             else if (levelName.equalsIgnoreCase("WARN"))
  +             else if (levelName.equalsIgnoreCase(STR_WARN))
                {
                    level = WARN;
                }
  -             else if (levelName.equalsIgnoreCase("ERROR"))
  +             else if (levelName.equalsIgnoreCase(STR_ERROR))
                {
                    level = ERROR;
                }
  -             else if (levelName.equalsIgnoreCase("FATAL"))
  +             else if (levelName.equalsIgnoreCase(STR_FATAL))
                {
                    level = FATAL;
                }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to