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
Thought this was a genuine defect but it turns out that my console size was limited, and caused the old content past 80000 characters to be cut off.
Right click on the console for the preferences and increase the console size limit.
Check your log4j.properties file
Check easy example here at here.
Go to Run configurations in your eclipse then -VM arguments add this: -Dlog4j.configuration=log4j-config_folder/log4j.xml
replace log4j-config_folder with your folder structure where you have your log4j.xml file
Makes sure when running junit test cases, you have the log4j.properties or log4j.xml file in your test/resources folder.
My situation was solved by specifing the VM argument to the JAVA program being debugged, I assume you can also set this in `eclipse.ini file aswell:
There is a case I make: exception happen in somewhere, but I catched the exception without print anything, thus the code didn't even reach the log4j code, so no output.