古詩詞大全網 - 四字成語 - eclipse中用 log4j 控制臺不顯示日誌 ,配置如下:

eclipse中用 log4j 控制臺不顯示日誌 ,配置如下:

#-------------------------------- ?

# ?

log4j.rootLogger=INFO, stdout ?

log4j.logger.com.ibatis = DEBUG ?

log4j.logger.com.ibatis.common.jdbc.SimpleDataSource = DEBUG ?

log4j.logger.com.ibatis.common.jdbc.ScriptRunner = DEBUG ?

log4j.logger.com.ibatis.sqlmap.engine.impl.SqlMapClientDelegate = DEBUG ?

log4j.logger.java.sql.Connection = DEBUG ?

log4j.logger.java.sql.Statement = DEBUG ?

log4j.logger.java.sql.PreparedStatement = DEBUG?

log4j.logger.java.sql.ResultSet = INFO ?

log4j.appender.stdout=org.apache.log4j.ConsoleAppender ?

log4j.appender.stdout.layout=org.apache.log4j.PatternLayout ?

1. 在運行的VM的參數裏面增加-Dlog4j.debug 打印出log4j的測試信息。

2. 或者在VM參數裏面強制增加log4j配置文件地址:?-Dlog4j.configuration=log4j-

config_folder/log4j.xml

壹般妳應該通過第壹步找到原因然後根據情況解決

如何加參數:

如果妳是用的run/debug

右鍵->run/debug下面有壹個run configurations/debug configurations->(x)=Argument

s->下方有個VM arguments: 把參數加到裏面,選apply和run/debug就可以了。

2. 如果妳是用的myeclipse,要在Tomcat->Tomcat n.x->JDK->Optional Java VM?

arguments下增加?-Dlog4j.debug

原文:/questions/3501355/log4j-output-not-displayed-in-

eclipse-console

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

java?eclipse?junit?log4j

share|improve this questionedited?Aug 17 '10 at

10:21leppie68.9k8106203asked?Aug 17 '10 at 10:11javaExpert1242210

1?Did you already got the answer? Their is nearly every possible solution explained,

so it would be interesting, whether one helped. –?user357206Sep 2 '10 at 7:52

add a comment

11 Answers

active?oldest?votes

up vote?11?down vote

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

share|improve this answeranswered?Aug 17 '10 at 12:24Huzi--- Javiator51945

Thanks for the suggestion. This way it worked! Although I'm still a bit annoyed for?

two reasons: 1) I thought if I used the BasicConfigurator.configure() I didn't have to?

bother having the log4j.properties 2) When I run a simple JUnit test I just want to right?

clik and "run", not having to define a configuration I've tried again my original test,?

but adding the following line to see if it was using some variable defined somewhere

in Eclipse: System.out.println(System.getProperty("log4j.configuration")); But it prints

out "null" –?javaExpertAug 17 '10 at 13:50hmmm.. interesting.. k ll get back to yu –

Huzi--- Javiator?Aug 18 '10 at 8:59

add a comment

up vote?8?down vote

Look in the?log4j.properties?or?log4j.xml?file for the log level. It's probably set

to?ERROR?instead of?DEBUG

share|improve this answeranswered?Aug 17 '10 at 10:15Aaron Digulla153k36236405

1?Thanks for the reply Aaron. I have checked the log4.properties and it was set on

INFO. I have now changed it to DEBUG, but it doesn't make any difference. Any?

other idea? log4j.rootLogger=DEBUG, stdout

log4j.appender.stdout=org.apache.log4j.ConsoleAppender

log4j.appender.stdout.layout=org.apache.log4j.PatternLayout

log4j.appender.stdout.layout.ConversionPattern=%t:%d{ddMMMyy HH:mm:ss.SSS}

%-5p (%F:%L) %m%n –?javaExpert?Aug 17 '10 at 10:2310?add?-Dlog4j.debug?to your

VM environment startup properties to have log4j print out it's debugging info -

perhaps a different log4j configuration file is being picked up on the classpath (such

as one bundled inside a JAR) than the one you intend –?matt b?Aug 17 '10 at

11:35@javaExpert: In that case, it find a different log4j.properties somewhere on?

the classpath. Look into your JARs, too! –?Aaron Digulla?Aug 17 '10 at 12:23

add a comment

up vote?5?down vote

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.