For some reason my Eclipse console no longer displays Log4j INFO and DEBUG statements when I run JUnit tests. In terms of code there hasn't been any change, so it must something to do with the Eclipse configuration.
All I do in my Unit test is the following and for some reason ONLY the ERROR statement is displayed in the Eclipse console. Why? Where shall I look for clues?
public class SampleTest
{
private static final Logger LOGGER = Logger.getLogger(SampleTest.class);
@Before
public void init() throws Exception
{
// Log4J junit configuration.
BasicConfigurator.configure();
LOGGER.info("INFO TEST");
LOGGER.debug("DEBUG TEST");
LOGGER.error("ERROR TEST");
}
}
Details:
- log4j-1.2.6.jar
- junit-4.6.jar Eclipse
- IDE for Java Developers, Version: Helios Release, Build id: 20100617-1415
Sounds like log4j picks up another configuration file than the one you think it does.
Put a breakpoint in log4j where the file is opened and have a look at the files getAbsolutePath().
Look in the
log4j.properties
orlog4j.xml
file for the log level. It's probably set toERROR
instead ofDEBUG
Check for log4j configuration files in your output (i.e. bin or target/classes) directory or within generated project artifacts (.jar/.war/.ear). If this is on your classpath it gets picked up by log4j.
I once had an issue like this, when i downloadad a lib from Amazon (for Amazon webservices) and that jar file contained a log4j.properties and somehow that was used instead of my good old, self configed log4j. Worth a check.
The Eclipse Console Window has a Filter Property (in some cases only system.err is active).
Rigt click into Eclipse console window -> Preferences -> Console and ensure that checkbox
Show when Program writes to standard out
is active.
Alternatively you can configure log4j to write alway to System.err like this: