The standard Priority class implements

Priority toPriority(String level)
and 
Priority toPriority(String level, Priority default)

It also implements
Priority toPriority(int intLevel)
but ****not****
Priority toPriority(int intLevel, Priority default)

The lack of this last method causes problems when 
defining custom priorities; the derived priority class
typically calls the inherited method if it doesn't understand
a level string or int it is passed, but because of the lack of
a default parameter, it cannot control what default value is
used if toPriority(int) is called with a totally unknown int value.

It's also a little inconsistent/asymmetric not to have the
Priority toPriority(int intLevel, Priority default) method defined.

Example of custom priority class making use of this patch:

Proposed patch:


Index: Priority.java
===================================================================
RCS file: /home/cvspublic/jakarta-log4j/org/apache/log4j/Priority.java,v
retrieving revision 1.5
diff -u -r1.5 Priority.java
--- Priority.java       2001/01/19 16:45:28     1.5
+++ Priority.java       2001/02/06 13:05:47
@@ -134,20 +134,30 @@
   }
 
   /**
-    Convert an integerq passed as argument to a priority. If the
-    conversion fails, then this method returns {@link #DEBUG}.      
+    Convert an integer passed as argument to a priority. If the
+    conversion fails, then this method returns {@link #DEBUG}.
 
   */
   public
   static
   Priority toPriority(int val) {
+    return toPriority(val, Priority.DEBUG);
+  }
+
+  /**
+    Convert an integer passed as argument to a priority. If the
+    conversion fails, then this method returns the specified default.
+  */
+  public
+  static
+  Priority toPriority(int val, Priority defaultPriority) {
     switch(val) {
     case DEBUG_INT: return DEBUG;
     case INFO_INT: return INFO;
     case WARN_INT: return WARN;
     case ERROR_INT: return ERROR;
     case FATAL_INT: return FATAL;
-    default: return DEBUG;
+    default: return defaultPriority;
     }
   }
 
@@ -171,5 +181,6 @@
     if(s.equals("FATAL")) return Priority.FATAL;
     return defaultPriority;
   }
+
 
 }

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

Reply via email to