slf4j + log4j问题
我试图在我的 java 应用程序中使用 log4j 配置 slf4j 但没有成功。 我的 log4j 文件如下所示:
log4j.rootLogger=DEBUG,stdout
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d [%t] %-5p %X{file} %c{1} - %m%n
log4j.logger.lt.hltech.tools.webcrawler=DEBUG,webcrawler
log4j.additivity.lt.hltech.ws.webcrawler=false
log4j.logger.webcrawler=DEBUG,webcrawler
log4j.additivity.webcrawler=false
log4j.appender.webcrawler=org.apache.log4j.DailyRollingFileAppender
log4j.appender.webcrawler.File=D:\\Projects\\IntellijIdeaProjects\\hltech_tools\\WebCrawler\\crawling.log
log4j.appender.webcrawler.DatePattern='.'yyyy-MM-dd
log4j.appender.webcrawler.layout=org.apache.log4j.PatternLayout
log4j.appender.webcrawler.layout.ConversionPattern=%d [%t] %-5p %X{file} %c{1} %m%n
log4j.appender.webcrawler.ImmediateFlush=true
jar 文件中的 MANIFEST.MF 如下所示:
Manifest-Version: 1.0
Ant-Version: Apache Ant 1.8.2
Created-By: 1.5.0_20-b02 (Sun Microsystems Inc.)
Main-Class: lt.hltech.tools.webcrawler.main.TopicalCrawler
Class-Path: ../../lib/antlr-2.7.6.jar ../../lib/asm-attrs.jar ../../li
b/asm.jar ../../lib/axis-1.4.jar ../../lib/axis-ant-1.4.jar ../../lib
/axis-spring-provider-0.1.0.jar ../../lib/cglib-2.1.3.jar ../../lib/c
heckstyle-5.4-all.jar ../../lib/checkstyle-5.4.jar ../../lib/commons-
collections-2.1.1.jar ../../lib/commons-logging-1.1.1.jar ../../lib/c
ommons-logging-adapters-1.1.1.jar ../../lib/commons-logging-api-1.1.1
.jar ../../lib/dom4j-1.6.1.jar ../../lib/ehcache-1.2.3.jar ../../lib/
hibernate-annotations.jar ../../lib/hibernate-commons-annotations.jar
../../lib/hibernate-entitymanager.jar ../../lib/hibernate-tools.jar
../../lib/hibernate3.jar ../../lib/javassist.jar ../../lib/jaxen-1.1.
1.jar ../../lib/jaxrpc-1.1-axis14.jar ../../lib/jdbc2_0-stdext.jar ..
/../lib/jericho-html-3.1.jar ../../lib/jing.jar ../../lib/jta.jar ../
../lib/junit.jar ../../lib/log4j-1.2.9.jar ../../lib/mysql-connector-
java-5.1.6-bin.jar ../../lib/ontopia-vizlet.jar ../../lib/ontopia.jar
../../lib/pmd-4.2.6.jar ../../lib/signed-vizlet.jar ../../lib/slf4j-
api-1.5.11.jar ../../lib/slf4j-log4j12-1.5.11.jar ../../lib/xercesImp
l-2.6.2.jar ../../src/main/config/log4j.properties
我添加了 slf4j-log4j12-1.5.11.jar、log4j-1.2.9.jar、slf4j- api-1.5.11.jar 甚至 log4j.properties 在我的类路径中。但日志记录不起作用。
有什么想法如何解决吗? 谢谢
I'm trying to configure slf4j with log4j in my java application and I get no success.
My log4j file looks like this:
log4j.rootLogger=DEBUG,stdout
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d [%t] %-5p %X{file} %c{1} - %m%n
log4j.logger.lt.hltech.tools.webcrawler=DEBUG,webcrawler
log4j.additivity.lt.hltech.ws.webcrawler=false
log4j.logger.webcrawler=DEBUG,webcrawler
log4j.additivity.webcrawler=false
log4j.appender.webcrawler=org.apache.log4j.DailyRollingFileAppender
log4j.appender.webcrawler.File=D:\\Projects\\IntellijIdeaProjects\\hltech_tools\\WebCrawler\\crawling.log
log4j.appender.webcrawler.DatePattern='.'yyyy-MM-dd
log4j.appender.webcrawler.layout=org.apache.log4j.PatternLayout
log4j.appender.webcrawler.layout.ConversionPattern=%d [%t] %-5p %X{file} %c{1} %m%n
log4j.appender.webcrawler.ImmediateFlush=true
MANIFEST.MF in jar file looks like this:
Manifest-Version: 1.0
Ant-Version: Apache Ant 1.8.2
Created-By: 1.5.0_20-b02 (Sun Microsystems Inc.)
Main-Class: lt.hltech.tools.webcrawler.main.TopicalCrawler
Class-Path: ../../lib/antlr-2.7.6.jar ../../lib/asm-attrs.jar ../../li
b/asm.jar ../../lib/axis-1.4.jar ../../lib/axis-ant-1.4.jar ../../lib
/axis-spring-provider-0.1.0.jar ../../lib/cglib-2.1.3.jar ../../lib/c
heckstyle-5.4-all.jar ../../lib/checkstyle-5.4.jar ../../lib/commons-
collections-2.1.1.jar ../../lib/commons-logging-1.1.1.jar ../../lib/c
ommons-logging-adapters-1.1.1.jar ../../lib/commons-logging-api-1.1.1
.jar ../../lib/dom4j-1.6.1.jar ../../lib/ehcache-1.2.3.jar ../../lib/
hibernate-annotations.jar ../../lib/hibernate-commons-annotations.jar
../../lib/hibernate-entitymanager.jar ../../lib/hibernate-tools.jar
../../lib/hibernate3.jar ../../lib/javassist.jar ../../lib/jaxen-1.1.
1.jar ../../lib/jaxrpc-1.1-axis14.jar ../../lib/jdbc2_0-stdext.jar ..
/../lib/jericho-html-3.1.jar ../../lib/jing.jar ../../lib/jta.jar ../
../lib/junit.jar ../../lib/log4j-1.2.9.jar ../../lib/mysql-connector-
java-5.1.6-bin.jar ../../lib/ontopia-vizlet.jar ../../lib/ontopia.jar
../../lib/pmd-4.2.6.jar ../../lib/signed-vizlet.jar ../../lib/slf4j-
api-1.5.11.jar ../../lib/slf4j-log4j12-1.5.11.jar ../../lib/xercesImp
l-2.6.2.jar ../../src/main/config/log4j.properties
I have added slf4j-log4j12-1.5.11.jar, log4j-1.2.9.jar, slf4j-
api-1.5.11.jar and even log4j.properties in my classpath. But the logging doesnt work.
Any ideas how to solve it?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试使用 slf4j-api-1.7.5 、 log4j-1.2.17 和 slf4j-log4j12-1.7.5 并确保类路径中有一个活页夹 jar(仅 slf4j-log4j12-1.7.5.jar)。然后将 log4j.properties 文件添加到 src/main/resources 中。只需尝试一下这个 log4j.properties 示例即可。
Try out with slf4j-api-1.7.5 , log4j-1.2.17 and slf4j-log4j12-1.7.5 and make sure U have one binder jar (only slf4j-log4j12-1.7.5.jar) in your class path. Then add log4j.properties file into
src/main/resources
. Just try out with this log4j.properties example.在类路径的末尾有:
至 I知道,classpath只能包含jar、zip或目录。添加其他文件没有任何效果。
尝试将您的属性打包到 jar 文件中或包含包含它的目录。
At the end of your classpath there's:
As far as I know, classpath can only contain jars, zips or directories. Adding other files has no effect.
Try packing your properties into a jar file or include the directory that contains it.