我使用weblogic在服务器上部署了两个应用程序。我为每个应用程序创建了单独的属性文件和配置servlet。但发生的问题是记录器附加到最新部署的应用程序的日志文件。这个代码在tomcat上运行良好,但是当部署在weblogic服务器上时,它的行为就像只有一个实例在工作,而且这也是最新的。针对多个应用程序使用log4j的应用程序级日志在weblogic上无法正常工作
log4j.properties文件,我把在WEB-INF:
log4j.rootLogger=INFO, R
log4j.appender.R=org.apache.log4j.RollingFileAppender
log4j.appender.R.File=C:abc.log
log4j.appender.R.MaxFileSize=10MB
log4j.appender.R.MaxBackupIndex=10
log4j.appender.R.Append=true
log4j.appender.R.layout=org.apache.log4j.PatternLayout
log4j.appender.R.layout.ConversionPattern=%d %-5p %c (%F:%L) - %m%n
我已经把的log4j-1.2.14.jar在lib文件夹,所有的图书馆都居住。
在servlet初始化Inititalising它()方法:
public void init() throws ServletException {
logger.info("Servlet...................");
super.init();
String prefix = getServletContext().getRealPath("/");
String log4j = getServletContext().getInitParameter"log4jConfig");
if (log4j != null) {
PropertyConfigurator.configure(prefix + log4j);
}
}
和web.xml条目是:
<context-param>
<param-name>log4jConfig</param-name>
<param-value>/WEB-INF/log4j.properties</param-value>
</context-param>
我至少可以看到2个拼写错误。在你的代码文件中缺少斜杠和'getServletContext()。getInitParameter“log4jConfig”)''File = C:abc.log''(' – JoseK