`
czg514404424
  • 浏览: 3700 次
社区版块
存档分类
最新评论

log4j:ERROR setFile(null,true) call failed.

阅读更多
log4j:ERROR setFile(null,true) call failed.
java.io.FileNotFoundException: log\spring.log (系统找不到指定的路径。)
at java.io.FileOutputStream.openAppend(Native Method)
at java.io.FileOutputStream.<init>(FileOutputStream.java:177)
at java.io.FileOutputStream.<init>(FileOutputStream.java:102)
at org.apache.log4j.FileAppender.setFile(FileAppender.java:273)
at org.apache.log4j.FileAppender.activateOptions(FileAppender.java:152)
at org.apache.log4j.DailyRollingFileAppender.activateOptions(DailyRollingFileAppender.java:206)
at org.apache.log4j.config.PropertySetter.activate(PropertySetter.java:247)
at org.apache.log4j.config.PropertySetter.setProperties(PropertySetter.java:123)
at org.apache.log4j.config.PropertySetter.setProperties(PropertySetter.java:87)
at org.apache.log4j.PropertyConfigurator.parseAppender(PropertyConfigurator.java:645)
at org.apache.log4j.PropertyConfigurator.parseCategory(PropertyConfigurator.java:603)
at org.apache.log4j.PropertyConfigurator.configureRootCategory(PropertyConfigurator.java:500)
at org.apache.log4j.PropertyConfigurator.doConfigure(PropertyConfigurator.java:406)
at org.apache.log4j.PropertyConfigurator.doConfigure(PropertyConfigurator.java:432)
at org.apache.log4j.helpers.OptionConverter.selectAndConfigure(OptionConverter.java:460)
at org.apache.log4j.LogManager.<clinit>(LogManager.java:113)
at org.apache.log4j.Logger.getLogger(Logger.java:94)
at com.juguo.niuniusearch.dao.RelevWordDAO.<init>(RelevWordDAO.java:22)
at com.juguo.niuniusearch.service.RelevWordService.<init>(RelevWordService.java:15)
at com.juguo.niuniusearch.servlet.Autocomplete.getDB(Autocomplete.java:61)
at com.juguo.niuniusearch.servlet.Autocomplete.doPost(Autocomplete.java:47)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:291)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:859)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:602)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
at java.lang.Thread.run(Thread.java:619)

一个web项目做日志时出现的错误

由log4j.appender.DailyRollingFile.File=log/spring.log,可以看出我们要新建一个log文件,我在myeclipse中项目底下,也确实建了log,但是还是找不到路径。
原因,启动Tomcat时,项目是在Tomcat路径下运行,所以我们要找到Tomcat的安装路径,然后在bin文件中新建一个log文件,就可以了。

下面是我log4j.properties内容

#log4j.rootLogger=FATAL ERROR WARN INFO DEBUG

log4j.rootLogger=DEBUG,consoleFile,DailyRollingFile

log4j.appender.consoleFile=org.apache.log4j.ConsoleAppender
log4j.appender.consoleFile.layout=org.apache.log4j.PatternLayout
log4j.appender.consoleFile.layout.ConversionPattern=[%-5p] %t %d %37c %3x - %m%n
log4j.appender.consoleFile.Threshold=INFO
log4j.appender.consoleFile.ImmediateFlush=true
log4j.appender.consoleFile.Target=System.out

log4j.appender.DailyRollingFile=org.apache.log4j.DailyRollingFileAppender
log4j.appender.DailyRollingFile.File=log/spring.log
log4j.appender.DailyRollingFile.DatePattern='.'yyyy-MM-dd
log4j.appender.DailyRollingFile.layout=org.apache.log4j.PatternLayout
log4j.appender.DailyRollingFile.layout.ConversionPattern=%d %-5p %37c - %m%n
log4j.appender.DailyRollingFile.Threshold=DEBUG
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics