Log4j output not displayed in Eclipse console

2019-01-22 02:29发布

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

17条回答
倾城 Initia
2楼-- · 2019-01-22 03:18

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.

查看更多
劫难
3楼-- · 2019-01-22 03:20

Check your log4j.properties file

Check easy example here at here.

查看更多
叼着烟拽天下
4楼-- · 2019-01-22 03:22

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

查看更多
乱世女痞
5楼-- · 2019-01-22 03:23

Makes sure when running junit test cases, you have the log4j.properties or log4j.xml file in your test/resources folder.

查看更多
ゆ 、 Hurt°
6楼-- · 2019-01-22 03:24

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:

enable-debug-level-in-eclipse

查看更多
虎瘦雄心在
7楼-- · 2019-01-22 03:26

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.

查看更多
登录 后发表回答