I have a program where Log4J starts up fine with a basic configuration, 
logging to std output, and then seems to forget how to log.  When I look 
closer, the problem seems to be due to multiple root category objects 
being created.  Example output:

  51 [Thread-2] INFO jmri  - Test message
  log4j:ERROR No appenders could be found for category 
(jmri.tests.symbolicprog.SymbolicProgTest).
  log4j:ERROR Please initialize the log4j system properly.

Note that it was logging OK, then seems to have lost its configuration. 

I've put the details below, in case I've made a mistake in my reasoning, 
but it looks to me like later Category.getInstance(...) calls get confused 
and create a new root Category object instead of using an existing 
configured one.

Can anybody suggest how I can debug this?  

Bob



Details:

In my main class, I've got:

   static org.apache.log4j.Category log = 
org.apache.log4j.Category.getInstance("jmri");

In the main proc itself, I initialize log4j & immediately test it:

   org.apache.log4j.BasicConfigurator.configure();
   log.info("Test message");
   System.out.println("log4j "+org.apache.log4j.Category.getRoot());

At this point, life is good.  Std output gets:

   0 [Thread-2] INFO jmri.progdebugger.ProgDebugger  - Test message
   log4j org.apache.log4j.spi.RootCategory@294279a

Note the address of the RootCategory object above.

I then start JUnit, which eventually gets to a specific 
SymbolicProgTest test class that contains

   static org.apache.log4j.Category log = 
org.apache.log4j.Category.getInstance(SymbolicProgTest.class.getName());

The full name of the SymbolicProgTest is jmri.tests.symbolicprog.SymbolicProgTest.  
One of its tests includes a log4j request of the form:

   log.info("message from log4j");
   System.out.println("log4j "+org.apache.log4j.Category.getRoot());

where I added that second statement to debug this problem.  The std output gets:

   log4j:ERROR No appenders could be found for category 
(jmri.tests.symbolicprog.SymbolicProgTest).
   log4j:ERROR Please initialize the log4j system properly.
   log4j org.apache.log4j.spi.RootCategory@282434d

Note that the RootCategory object's address in the third line is _different_ 
from what was seen earlier.  That's what makes me believe that log4j is creating
multiple roots.

System specifics:  Macintosh OS 9.1 with MRJ 2.2.5; log4j 1.1.3 using 
distributed .jar file; java compiler is CodeWarrior most recent patch level.

Any help, even debugging pointers, would be greatly appreciated.

Bob
-- 
--------------
Bob Jacobsen ([EMAIL PROTECTED], 510-486-7355, fax 510-495-2957)
Working off large email backlog from trip; if its urgent, call!

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

Reply via email to