log4j无法打印日志的问题

时间:2021-09-29 04:37:17

 http://www.webspherechina.net/club/thread-11960-1-1.html

 

这个问题提出来一直没人解决,最后找到毛病了,发在这里                  
生产系统升级后发现接口无法打印日志web层无法打印,service层可以打印,检查日志发现:
[09-12-15 15:53:45:617 CST] 00000030 SystemErr R log4j:ERROR Could not find value for key log4j.appender.appfile.layout
[09-12-15 15:53:45:618 CST] 00000030 SystemErr R log4j:WARN File option not set for appender [appfile].
[09-12-15 15:53:45:618 CST] 00000030 SystemErr R log4j:WARN Are you using FileAppender instead of ConsoleAppender?
[09-12-15 15:53:45:618 CST] 00000030 SystemErr R log4j:ERROR Either File or DatePattern options are not set for appender [appfile].
搜索到解决办法为:
目录
/opt/IBM/WebSphere/AppServer/profiles/AppSrv01/properties
增加一个文件名:
commons-logging.properties
内容为
org.apache.commons.logging.LogFactory=org.apache.commons.logging.impl.LogFactoryImpl
问题解决

 

或者在程序中增加

if ( System.getProperty("log4j.configuration") != null )
   PropertyConfigurator.configure(System.getProperty("log4j.configuration"));
  else
   BasicConfigurator.configure();