You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4j-user@logging.apache.org by Bob Jacobsen <Bo...@lbl.gov> on 2001/08/04 00:33:41 UTC
Log4J logging then stops; due to multiple root categories?
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 (Bob_Jacobsen@lbl.gov, 510-486-7355, fax 510-495-2957)
Working off large email backlog from trip; if its urgent, call!
---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: log4j-user-help@jakarta.apache.org
Re: Log4J logging then stops; due to multiple root categories?
Posted by Bob Jacobsen <Bo...@lbl.gov>.
Thank you! That was exactly the clue I needed to track this down!
In case anybody encounters this particular problem again, log4j works
fine if you initialize it _after_ JUnit, rather than before.
Specifically, if you put the log4j initialization in the base
testsuite definition (the public static Test suite() {} that appears
in the class that initializes JUnit), it works fine.
Bob
At 10:28 AM +0200 8/4/01, Ceki Gülcü wrote:
>Hello Bob,
>
>There is only one line of code that creates the root category and it
>is called when Category class is initialized. You probably have a
>situation where the Category class is loaded by multiple
>classloaders. I believe that junit uses its own class loader which
>explains what you are seeing. Regards, Ceki
>
>At 15:33 03.08.2001 -0700, Bob Jacobsen wrote:
>>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 (Bob_Jacobsen@lbl.gov, 510-486-7355, fax 510-495-2957)
>>Working off large email backlog from trip; if its urgent, call!
>>
>>---------------------------------------------------------------------
>>To unsubscribe, e-mail: log4j-user-unsubscribe@jakarta.apache.org
>>For additional commands, e-mail: log4j-user-help@jakarta.apache.org
>
>--
>Ceki Gülcü - http://qos.ch
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: log4j-user-unsubscribe@jakarta.apache.org
>For additional commands, e-mail: log4j-user-help@jakarta.apache.org
--
--------------
Bob Jacobsen (Bob_Jacobsen@lbl.gov, 510-486-7355, fax 510-495-2957)
Working off large email backlog from trip; if its urgent, call!
---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: log4j-user-help@jakarta.apache.org
Re: Log4J logging then stops; due to multiple root categories?
Posted by Ceki Gülcü <cg...@qos.ch>.
Hello Bob,
There is only one line of code that creates the root category and it is called when Category class is initialized. You probably have a situation where the Category class is loaded by multiple classloaders. I believe that junit uses its own class loader which explains what you are seeing. Regards, Ceki
At 15:33 03.08.2001 -0700, Bob Jacobsen wrote:
>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 (Bob_Jacobsen@lbl.gov, 510-486-7355, fax 510-495-2957)
>Working off large email backlog from trip; if its urgent, call!
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: log4j-user-unsubscribe@jakarta.apache.org
>For additional commands, e-mail: log4j-user-help@jakarta.apache.org
--
Ceki Gülcü - http://qos.ch
---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: log4j-user-help@jakarta.apache.org