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 Log4jLoggerImpl.java PoorMansLoggerImpl.java
Date Fri, 02 Sep 2005 13:24:52 GMT
arminw      2005/09/02 06:24:52

  Modified:    src/java/org/apache/ojb/broker/util/logging Tag:
                        OJB_1_0_RELEASE Log4jLoggerImpl.java
                        PoorMansLoggerImpl.java
  Log:
  minor improvements
  
  Revision  Changes    Path
  No                   revision
  No                   revision
  1.16.2.2  +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.16.2.1
  retrieving revision 1.16.2.2
  diff -u -r1.16.2.1 -r1.16.2.2
  --- Log4jLoggerImpl.java	3 Nov 2004 19:11:48 -0000	1.16.2.1
  +++ Log4jLoggerImpl.java	2 Sep 2005 13:24:52 -0000	1.16.2.2
  @@ -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;
  @@ -45,23 +44,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
  @@ -103,7 +91,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);
  @@ -112,21 +104,12 @@
               {
                   PropertyConfigurator.configure(url);
               }
  -
               // if file is not in classpath try ordinary filesystem lookup
  -            else if (configFile != "")
  -            {
  -                PropertyConfigurator.configure(configFile);
  -            }
               else
               {
  -                // no configuration available
  +                PropertyConfigurator.configure(configFile);
               }
           }
  -        else
  -        {
  -            // no configuration available
  -        }
       }
   
   	public Log4jLoggerImpl(String name)
  @@ -312,7 +295,7 @@
   	{
   		if (Level.WARN.isGreaterOrEqual(getLevel()))
   		{
  -			String toString = null;
  +			String toString;
   			try
   			{
   				toString = obj.toString();
  @@ -329,7 +312,7 @@
   	{
   		if (Level.WARN.isGreaterOrEqual(getLevel()))
   		{
  -			String toString = null;
  +			String toString;
   			try
   			{
   				toString = obj.toString();
  @@ -346,7 +329,7 @@
   	{
   		if (Level.ERROR.isGreaterOrEqual(getLevel()))
   		{
  -			String toString = null;
  +			String toString;
   			try
   			{
   				toString = obj.toString();
  @@ -363,7 +346,7 @@
   	{
   		if (Level.ERROR.isGreaterOrEqual(getLevel()))
   		{
  -			String toString = null;
  +			String toString;
   			try
   			{
   				toString = obj.toString();
  @@ -380,7 +363,7 @@
   	{
   		if (Level.FATAL.isGreaterOrEqual(getLevel()))
   		{
  -			String toString = null;
  +			String toString;
   			try
   			{
   				toString = obj.toString();
  @@ -397,7 +380,7 @@
   	{
   		if (Level.FATAL.isGreaterOrEqual(getLevel()))
   		{
  -			String toString = null;
  +			String toString;
   			try
   			{
   				toString = obj.toString();
  @@ -417,8 +400,17 @@
   
   	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;
  +    }
   
   	/**
   	 * @see org.apache.ojb.broker.util.configuration.Configurable#configure(Configuration)
  
  
  
  1.11.2.1  +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.11
  retrieving revision 1.11.2.1
  diff -u -r1.11 -r1.11.2.1
  --- PoorMansLoggerImpl.java	4 Apr 2004 23:53:38 -0000	1.11
  +++ PoorMansLoggerImpl.java	2 Sep 2005 13:24:52 -0000	1.11.2.1
  @@ -28,6 +28,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
  @@ -322,23 +335,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: ojb-dev-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-dev-help@db.apache.org


Mime
View raw message