logging-log4j-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Elias Ross <er...@m-qube.com>
Subject Thoughs on Level.java
Date Wed, 28 Jan 2004 07:45:45 GMT
On Tue, 2004-01-27 at 22:58, Elias Ross wrote:

>   Level ALWAYS = new Level(ALWAYS_INT, "INFO", 7);

Okay, looking at the JavaDoc, Level doesn't have a public constructor.
Why not?  At first glace it didn't make a whole lot of sense.  I then
realized it must have been done this way to allow configuration settings
like this:

  <level value="TRACE" class="org.somebody.CustomLevel" />

What Log4J does is load the class, then calls the toLevel(String) method
to return an actual object.  For this you need to create an overridden
Level.toLevel(String) method, which is part of the Level class. 

Personally, I think it rather annoying to have to build both
toLevel(String) and toLevel(int) methods.  The latter 'int' one doesn't
seen to be used in Log4J at all; the 'String' is only necessary when
converting DEBUG/ERROR/etc. to a real Level object.  Of course writing
those methods is trivial, but it might have worked to just as well to
design custom Levels to look like:

  <level class="org.somebody.CustomLevel#ALWAYS" />  (no value)

Where ALWAYS is a static member variable of an interface or class. 
"CustomLevel" wouldn't necessarily need to implement Level.  (If it did,
then maybe the "toLevel" method would be called, otherwise the member
variable would be retrieved.)

If you need a custom level for a certain class, you could make one up,
define it as a member and not have to write a separate class or
conversion routine.  E.g.:

public class MyClass { 
  
  public static Level ONETIME = new Level(100, "ONETIME", 7)

  public MyClass() {
    Logger.log(ONETIME, "One time message");
  }
}

I think it is confusing for people to have to subclass Level, when
really what they are really trying to do is create not just a Level, but
a collection of Levels.  It seems messy.

Just a humble thought...


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


Mime
View raw message