eclipse中用 log4j 控制台不显示日志 ,配置如下:
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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
#--------------------------------
#
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
原文:http://stackoverflow.com/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:50 hmmm.. 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:%dddMMMyy 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.
参考技术A 你好;日志的话需要用到以下三个包,你的包不全,可以先把包添加全了,然后就可以了;E:\Java\包\Hibernate配置的压缩包\slf4j-log4j12-1.5.8.jar
E:\Java\包\Hibernate配置的压缩包\log4j-1.2.15.jar
E:\Java\包\Hibernate配置的压缩包\slf4j-api-1.5.8.jar本回答被提问者采纳
以上是关于eclipse中用 log4j 控制台不显示日志 ,配置如下:的主要内容,如果未能解决你的问题,请参考以下文章
Eclipse、Spring、Wildfly log4j 日志记录
大数据调错系列之hadoop在开发工具控制台上打印不出日志的解决方法