Log4j and JUnit conflict

P

Paul Carey

Hi

I've written a class that extends TestCase and creates a Logger with
the following line:
private static Logger logger = Logger.getLogger( DataTest.class );

If no log4j config file is specified, I get the following errors when
I test DataTest in the awtui.TestRunner:

log4j:WARN No appenders could be found for logger
(poc.database.DataTest).
log4j:WARN Please initialize the log4j system properly.


If a specify a simple config file (below) I get the following errors:

log4j:ERROR A "org.apache.log4j.ConsoleAppender" object is not
assignable to a "
org.apache.log4j.Appender" variable.
log4j:ERROR The class "org.apache.log4j.Appender" was loaded by
log4j:ERROR [junit.runner.TestCaseClassLoader@4aeb52] whereas object
of type
log4j:ERROR "org.apache.log4j.ConsoleAppender" was loaded by
[sun.misc.Launcher$
AppClassLoader@12f6684].
log4j:ERROR Could not instantiate appender named "A1".
log4j:WARN No appenders could be found for logger
(poc.database.DataTest).
log4j:WARN Please initialize the log4j system properly.

If I specify the same config file but run the textui.TestRunner, it
works fine.

It's not much of a problem, but I'd appreciate if anyone could tell me
why this is happening.
Many thanks

Paul

# Set root logger level to DEBUG and its only appender to A1.
log4j.rootLogger=DEBUG, A1

# A1 is set to be a ConsoleAppender.
log4j.appender.A1=org.apache.log4j.ConsoleAppender

# A1 uses PatternLayout.
log4j.appender.A1.layout=org.apache.log4j.PatternLayout
log4j.appender.A1.layout.ConversionPattern=%-4r [%t] %-5p %c %x - %m%n
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

No members online now.

Forum statistics

Threads
473,777
Messages
2,569,604
Members
45,234
Latest member
SkyeWeems

Latest Threads

Top