logging-log4j-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Laurent Delaforge" <ldelaforg...@aol.com>
Subject Logger.setLevel()
Date Mon, 04 Aug 2003 07:18:34 GMT
Hi !

I have this code source :

public class TestLogging
{
     Logger mLoggerRoot = Logger.getRootLogger();
     Logger mClassLogger = Logger.getLogger(TestLogging.class.getName());
     Logger mClassLoggerSoon =
Logger.getLogger(TestLogging.class.getName() + ".soon");

     public void levelInheritance()
     {
         // init
         mClassLogger.setLevel(Level.DEBUG);
         mLoggerRoot.fatal("init : Level of " + mClassLogger.getName() +
" : " + mClassLogger.getEffectiveLevel());
         mLoggerRoot.fatal("init : Level of " +
mClassLoggerSoon.getName() + " : " + mClassLoggerSoon.getEffectiveLevel());

         // mClassLoggerSoon.setLevel(Level.FATAL); // try once with this
line uncommented and once again commented
         mClassLogger.setLevel(Level.FATAL);
         mLoggerRoot.fatal("1. Level of " + mClassLogger.getName() + " :
" + mClassLogger.getEffectiveLevel());
         mLoggerRoot.fatal("Level of " + mClassLoggerSoon.getName() + " :
" + mClassLoggerSoon.getEffectiveLevel());

         mClassLogger.setLevel(Level.DEBUG);
         mLoggerRoot.fatal("2. Level of " + mClassLogger.getName() + " :
" + mClassLogger.getEffectiveLevel());
         mLoggerRoot.fatal("Level of " + mClassLoggerSoon.getName() + " :
" + mClassLoggerSoon.getEffectiveLevel());
     }

     public static void main(String args[])
     {
         TestLogging lTestLogging = new TestLogging();
         lTestLogging.levelInheritance();
     }
}

Then you have :

root.levelInheritance [01 août 2003 15:42:43,587] 0
(TestLogging.java:112) main FATAL : init : Level of TestLogging : DEBUG
root.levelInheritance [01 août 2003 15:42:43,597] 10
(TestLogging.java:113) main FATAL : init : Level of TestLogging.soon : DEBUG
root.levelInheritance [01 août 2003 15:42:43,597] 10
(TestLogging.java:117) main FATAL : 1. Level of TestLogging : FATAL
root.levelInheritance [01 août 2003 15:42:43,597] 10
(TestLogging.java:118) main FATAL : Level of TestLogging.soon : FATAL
root.levelInheritance [01 août 2003 15:42:43,627] 40
(TestLogging.java:121) main FATAL : 2. Level of TestLogging : DEBUG
root.levelInheritance [01 août 2003 15:42:43,627] 40
(TestLogging.java:122) main FATAL : Level of TestLogging.soon : DEBUG <--

1. when we set TestLogging to level FATAL i think it is normal that
TestLogging.soon become FATAL too,
because it is not possible for a logger to have his level 'lower' than
his ancestor.
(So, for this case, it was not possible that level of TestLogging was
FATAL and level of TestLogging.soon was DEBUG)

2. when we set TestLogging to level DEBUG i don't think it is normal
that mClassLoggerSoon become DEBUG too,
because it IS possible for a logger to have his level 'higher' than his
ancestor.
(So, for this case, it was not possible that level of TestLogging was
DEBUG and level of TestLogging.soon was FATAL)

My question :
-----------------
Can you explain to me why in the case 2., level of TestLogging.soon
become DEBUG and doesn't keep its level FATAL.


Notice :
if you uncomment the line "mClassLoggerSoon.setLevel(Level.FATAL);",
there is no problem...

root.levelInheritance [01 août 2003 15:39:30,379] 0
(TestLogging.java:112) main FATAL : init : Level of TestLogging : DEBUG
root.levelInheritance [01 août 2003 15:39:30,389] 10
(TestLogging.java:113) main FATAL : init : Level of TestLogging.soon : DEBUG
root.levelInheritance [01 août 2003 15:39:30,389] 10
(TestLogging.java:118) main FATAL : 1. Level of TestLogging : FATAL
root.levelInheritance [01 août 2003 15:39:30,389] 10
(TestLogging.java:119) main FATAL : Level of TestLogging.soon : FATAL
root.levelInheritance [01 août 2003 15:39:30,449] 70
(TestLogging.java:122) main FATAL : 2. Level of TestLogging : DEBUG
root.levelInheritance [01 août 2003 15:39:30,449] 70
(TestLogging.java:123) main FATAL : Level of TestLogging.soon : FATAL
<-- NOW THIS IS NORMAL

Thank you


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


Mime
View raw message