开发者

LOG4J as singleton, closing appenders on server stop and start (Attempted to append to closed appender)

开发者 https://www.devze.com 2023-01-26 05:47 出处:网络
We have a j2ee web environment. The server is configured to share session and possibly classloaders across multiple webapps. Basically, one classloader could server multiple web apps.

We have a j2ee web environment. The server is configured to share session and possibly classloaders across multiple webapps. Basically, one classloader could server multiple web apps.

This seems to cause issues with log4j. Different webapps could have different log4j configurations but the logging may stop in one file.

We get the following error:

log4j:ERROR Attempted to append to closed appender named [mylogger]

Server: websphere6+ Log4j: 1.4.2 Java: 1.5

Example log4j.properties (webapp1):

log4j.appender.R=org.apache.log4j.RollingFileAppender
log4j.appender.R.File=/usr/local/file1.log
log4j.additivity.com.app=false

Example 开发者_运维技巧log4j.properties (webapp2):

log4j.appender.Z=org.apache.log4j.RollingFileAppender
log4j.appender.Z.File=/usr/local/file2.log
log4j.additivity.com.app=false

Right now, logging from webapp2 may appear in the webapp1 logs and vice verse. We don't want that.


Log4j is probably initializing only once and loading randomly one or the other log4j.properties.

In our case, we decided for each WebApp to have an separate classloader. This way, we can decide to change Log Level on other framework like Spring or iBatis, for each WebApp.

The best way to debug Classloader (very common with WebSphere) is to find out which Log4j jar you are using and which log4.properties is used.

URL url = Logger.class.getProtectionDomain().getCodeSource().getLocation();
System.out.println("Sourcing Log4j from " + url
0

精彩评论

暂无评论...
验证码 换一张
取 消