I have been playing around with Namespace hierarchies and additivity and
have come across some behaviour which does not seem right.


The following code exhibits the problem:

public void testLoggerAdditivity() {
   Hierarchy h = new Hierarchy();
   Logger logger1 = h.getLoggerFor("A");
   logger1.setPriority(Priority.DEBUG);
   Logger logger2 = h.getLoggerFor("A.B");
   logger2.setPriority(Priority.DEBUG);
   Logger logger3 = h.getLoggerFor("A.B.C");
   logger3.setPriority(Priority.DEBUG);
   final String pattern =
      "%7.7{priority} %5.5{time}   [%8.8{category}] "
         + "(%{context}): %{message}\\n%{throwable}";
   final PatternFormatter formatter = new PatternFormatter(pattern);
   File file1 = new File("LKAdd1.txt");
   try {
      FileTarget target1 = new FileTarget(file1, false, formatter);
      PriorityFilter filter = new PriorityFilter(Priority.ERROR);
      //Set log targets of logger
      logger1.setLogTargets(new LogTarget[] { target1, filter });
      logger1.setAdditivity(true);
      File file2 = new File("LKAdd2.txt");
      FileTarget target2 = new FileTarget(file2, false, formatter);
      logger2.setLogTargets(new LogTarget[] { target2, filter });
   }
   catch (IOException ioe) {
   }
   logger2.setAdditivity(true);
   logger3.setAdditivity(true);
   logger1.info("Additivity Message1");
   logger2.info("Additivity Message2");
   logger3.info("Additivity Message3");
}

Having setup a 3 level hierarchy, I attach targets to levels 1 and 2 (but
not 3). However the results written to the files LKAdd1.txt are:
INFO    10087   [A       ] (): Additivity Message1
INFO    10087   [A.B     ] (): Additivity Message2
and the results written to LKAdd2.txt are:
INFO    10087   [A.B     ] (): Additivity Message2
INFO    10087   [A.B.C   ] (): Additivity Message3

I would have assumed that the text logged to logger3 would also appear in
the target attached to logger1.

It is prevented from doing so by the following chunk of code in the log
method of class Logger:

            if( m_logTargetsForceSet && m_additivity && null != m_parent )
            {
                m_parent.output( event );
            }

m_logTargetsForceSet  is only set when a target is added but as logger3
uses the inherited handler and not one of its own, it only logs to
LKAdd2.txt and refuses to log to any parent targets.

I could not find any description as to how additivity is actually handled
so is this a defect?



****************************************************************
NOTICE - This message is intended only for the use of the 
addressee named above and may contain privileged and 
confidential information.  If you are not the intended recipient
of this message you are hereby notified that you must not 
disseminate, copy or take any action based upon it.  If you 
received this message in error please notify HIC immediately.
Any views expressed in this message are those of the individual
sender, except where the sender specifically states them to be
the views of HIC.
****************************************************************

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

Reply via email to