logging-log4j-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Ceki Gülcü <c...@qos.ch>
Subject RE: Priority.getAllPossiblePriorities() bug reported yet?
Date Wed, 09 Apr 2003 18:59:13 GMT

The Level.equals method is omitted by design. Levels are designed to be 
flyweights such that there can only be one instance of each level at any 
time. In the existing code for various convoluted reasons this is not the 
case because (Priority.DEBUG == Level.DEBUG) is false. Hiding this bug with 
an equals method will not fix it.

To remedy this inconsistency, I intend to remove the static fields 
Priority.DEBUG through Priority.FATAL. Moreover, the 
Priority.getAllPossiblePriorities is broken because it does not take into 
consideration custom levels. A better approach would have been to allow 
custom levels to be registered with some registry (perhaps a utility class) 
and let class respond to requests of type getAllPossibleLevels().

To address your specific problem, I would recommend writing your own method 
which returns the list of known levels, for example:

import org.apache.log4j.Level;

class LevelSupport {

  public static Level[] getAllPossibleLevels() {
     return new Level[] {
       Level.FATAL, Level.ERROR, Level.WARN, Level.INFO, Level.DEBUG

This should solve your problem. Right?

At 01:37 PM 4/9/2003 -0400, DJohnson@desknetinc.com wrote:
>Actually, it doesn't help in this case.  The reason it doesn't is that
>there is no equals() method of Level which would allow the expression
>"Level.ERROR.equals(Priority.ERROR)" to evaluate as true.  Since I was
>using the returned list of priorities as keys to a Map, and then
>attempting to later perform a lookup in that map using the Level from a
>LoggingEvent, the fact that Level.INFO is not the same object as
>Priority.INFO becomes significant.
>Yoav's suggestion for changing getAllPossiblePriorities would work, but it
>would be disruptive of existing code, which I assume is the reason for
>deprecating instead of removing the method immediately.  The smoothest
>transition would be afforded by implementing a good equals() method in
>Please respond to "Log4J Users List" <log4j-user@jakarta.apache.org>
>To:     "Log4J Users List" <log4j-user@jakarta.apache.org>
>Subject:        RE: Priority.getAllPossiblePriorities() bug reported yet?
>As Yoav said, the method Priority.getAllPossiblePriorities() is likely to
>disappear some time in the future. Moreover, if you look closely in the
>code of Priority.java class, you will see that all the static "priorities"
>are actually of type Level. Does this help?

Ceki  For log4j documentation consider "The complete log4j manual"

To unsubscribe, e-mail: log4j-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: log4j-user-help@jakarta.apache.org

View raw message