问题描述
- 关于log4j:ERROR setFile(null,true) call failed.
-
在myeclipse中从外部导入了一个web项目:已经将log4j.properties中的日志输出路径修改为绝对路径,并且在此绝对路径中找到该日志文件,但是在运行中,始终去找“ homecallcenterlogscsrlogs”这个路径?这是哪里出了问题,求高手解答!!
错误信息如下:
log4j:ERROR setFile(null,true) call failed.
java.io.FileNotFoundException: homecallcenterlogscsrlogsjECF_2015-04-09.log (系统找不到指定的路径。)
at java.io.FileOutputStream.openAppend(Native Method)
at java.io.FileOutputStream.(FileOutputStream.java:177)
at java.io.FileOutputStream.(FileOutputStream.java:102)
at org.apache.log4j.FileAppender.setFile(FileAppender.java:282)
at org.apache.log4j.FileAppender.activateOptions(FileAppender.java:161)
at enterprise.celerity.ac.util.IContactLogAppender.activateOptions(IContactLogAppender.java:44)
at org.apache.log4j.config.PropertySetter.activate(PropertySetter.java:256)
at org.apache.log4j.config.PropertySetter.setProperties(PropertySetter.java:132)
at org.apache.log4j.config.PropertySetter.setProperties(PropertySetter.java:96)
at org.apache.log4j.PropertyConfigurator.parseAppender(PropertyConfigurator.java:654)
at org.apache.log4j.PropertyConfigurator.parseCategory(PropertyConfigurator.java:612)
at org.apache.log4j.PropertyConfigurator.parseCatsAndRenderers(PropertyConfigurator.java:533)
at org.apache.log4j.PropertyConfigurator.doConfigure(PropertyConfigurator.java:417)
at org.apache.log4j.PropertyConfigurator.doConfigure(PropertyConfigurator.java:441)
at org.apache.log4j.helpers.OptionConverter.selectAndConfigure(OptionConverter.java:468)
at org.apache.log4j.LogManager.(LogManager.java:122)
at org.apache.log4j.Logger.getLogger(Logger.java:103)
at org.apache.commons.logging.impl.Log4JLogger.getLogger(Log4JLogger.java:283)
at org.apache.commons.logging.impl.Log4JLogger.(Log4JLogger.java:108)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
at org.apache.commons.logging.impl.LogFactoryImpl.createLogFromClass(LogFactoryImpl.java:1116)
at org.apache.commons.logging.impl.LogFactoryImpl.discoverLogImplementation(LogFactoryImpl.java:914)
at org.apache.commons.logging.impl.LogFactoryImpl.newInstance(LogFactoryImpl.java:604)
at org.apache.commons.logging.impl.LogFactoryImpl.getInstance(LogFactoryImpl.java:336)
at org.apache.commons.logging.LogFactory.getLog(LogFactory.java:704)
at org.apache.catalina.core.ContainerBase.getLogger(ContainerBase.java:381)
at org.apache.catalina.core.StandardContext.start(StandardContext.java:4119)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:760)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:740)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:544)
at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:926)
at org.apache.catalina.startup.HostConfig.deployDirectories(HostConfig.java:889)
at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:492)
at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1149)
at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:311)
at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:120)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1022)
at org.apache.catalina.core.StandardHost.start(StandardHost.java:736)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1014)
at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:443)
at org.apache.catalina.core.StandardService.start(StandardService.java:448)
at org.apache.catalina.core.StandardServer.start(StandardServer.java:700)
at org.apache.catalina.startup.Catalina.start(Catalina.java:552)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:295)
解决方案
第一,需要知道jvm虚拟机本来就有apache的东西,即像common-ioxxx之类的部分api已经集成在jdk里;
第二,如果你引用的第三方jar包,里面有一份log4j.properties文件的话,那么还是会被覆盖掉。
第三,jvm启动web或者app时,默认加载当前classpath的log4j.properties,然后才是你自己的log4j.properties
看看上面三个建议能帮得上你忙吗。
解决方案二:
我搜索了网上所有关于log4j的配置信息,并正确配置了log4j.properties中日志输出为本地的绝对路径。
------问题依然出现
好吧,不经意间做了如下操作:web项目右键--myeclipse ---run validation验证所有都选择“是”,重新运行
竟然发现问题解决了。
问题分析:web项目权限不足,无法搜索本地计算机的绝对路径。
**验证后,web项目拥有权限。**