Sie sind hier » Optionen » PERLE IOLAN STS Rack Series «. Local Console Port, RS232 on RJ45 with DB9 adapter ( provided ). Network, 10/100/1000-base. 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. Alternatively you can configure log4j to write alway to System.err like this.
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?
Details:
- log4j-1.2.6.jar
- junit-4.6.jar Eclipse
- IDE for Java Developers, Version:Helios Release, Build id:20100617-1415
![Sts Sts](/uploads/1/2/5/8/125832278/162312662.gif)
99.2k16 gold badges170 silver badges277 bronze badges
javaExpertjavaExpert2692 gold badges7 silver badges12 bronze badges
17 Answers
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
Huzi--- Javiator![Perle iolan configuration Perle iolan configuration](/uploads/1/2/5/8/125832278/365671012.jpg)
1,6911 gold badge11 silver badges5 bronze badges
Look in the
Aaron DigullaAaron Digullalog4j.properties
or log4j.xml
file for the log level. It's probably set to ERROR
instead of DEBUG
253k88 gold badges489 silver badges712 bronze badges
Configuring with
BasicConfigurator.configure();
sets up a basic console appender set at debug. A project with the setup above and no other code (except for a test) should produce three lines of logging in the console. I cannot say anything else than 'it works for me'.Have you tried creating an empty project with just log4j and junit, with only the code above and ran it?
Also, in order to get the
@Before
method running:EDIT:
If you run more than one test at one time, each of them will call init before running.
In this case, if you had two tests, the first would have one logger and the second test would call init again, making it log twice (try it) - you should get 9 lines of logging in console with two tests.
You might want to use a static init method annotated with
@BeforeClass
to avoid this. Though this also happens across files, you might want to have a look at documentation on TestSuites in JUnit 4. And/or call BasicConfigurator.resetConfiguration();
in an @AfterClass annotated class, to remove all loggers after each test class / test suite.Also, the root logger is reused, so that if you set the root logger's level in a test method that runs early, it will keep this setting for all other tests that are run later, even if they are in different files. (will not happen when resetting configuration).
Testcase - this will cause 9 lines of logging:
Changing the init method reduces to the excepted six lines:
Your problem is probably caused in some other test class or test suite where the logging level of the root logger is set to ERROR, and not reset.
You could also test this out by resetting in the @BeforeClass method, before setting logging up.
Be advised that these changes might break expected logging for other test cases until it is fixed at all places. I suggest trying out how this works in a separate workspace/project to get a feel for how it works.
TormodTormod
One thing to note, if you have a log4j.properties file on your classpath you do not need to call BasicConfigurator. A description of how to configure the properties file is here.
You could pinpoint whether your IDE is causing the issue by trying to run this class from the command line with log4j.jar and log4j.properties on your classpath.
Jon FreedmanJon Freedman7,1604 gold badges31 silver badges48 bronze badges
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.
KirenKiren
Check your log4j.properties file
Check easy example here at here.
MaulzeyMaulzey1,0873 gold badges15 silver badges27 bronze badges
Makes sure when running junit test cases, you have the log4j.properties or log4j.xml file in your test/resources folder.
VenkatVenkat8861 gold badge11 silver badges20 bronze badges
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().
Thorbjørn Ravn AndersenThorbjørn Ravn Andersen58.6k25 gold badges153 silver badges293 bronze badges
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.
Adriaan KosterAdriaan Koster13k3 gold badges33 silver badges48 bronze badges
cajunesquecajunesque
Check that your
BivasBivaslog4j.properties
or log4j.xml
are copied to your IDE classpath and loads when calling BasicConfigurator.configure()
1,3591 gold badge10 silver badges17 bronze badges
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.
Zsolt JánosZsolt János
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.
Eric WangEric Wang9,3257 gold badges74 silver badges111 bronze badges
I had the same error.
I am using Jboss 7.1 AS. In the configuration file - standalone.xml edit the following tag. (stop your server and edit)
The ALL has the lowest possible rank and is intended to turn on all logging.
GGNGGN
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:
Nic WNic W
if the log4j.xml file is not in the project,and you are using tomcat, try going to tomcat instance and search for log4j. Try changing the consoleAppender level to debug and redeploy the application in tomcat. That might help.
RajanRajan1,0052 gold badges18 silver badges26 bronze badges
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:
Daniel SokolowskiDaniel Sokolowski8,5052 gold badges49 silver badges45 bronze badges