我正在尝试在我的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。但是日志记录不起作用。
任何想法如何解决? 感谢
答案 0 :(得分:1)
尝试使用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示例。
答案 1 :(得分:0)
在类路径的末尾有:
../../src/main/config/log4j.properties
就I know而言,classpath只能包含jar,zip或目录。添加其他文件无效。
尝试将您的属性打包到jar文件中或包含包含它的目录。