Search code examples
javalogginglog4jweblogic

log4j:ERROR Attempted to append to closed appender named


We have about 19 applications in our weblogic 8.1 server. Each application is an .Ear application with a few ejbs, mdb etc., Each application has a log4j properties defined in a .properties file somewhere in the filesystem.

We keep getting this error(below) in the server logs for all the applications. This exception is not caught in the application, the flow of the application does not stop, but we miss a log statement or two when this exception occurs.

log4j:ERROR Attempted to append to closed appender named

Note: I've looked up in the internet, i've not seen duplicate log4j.jar files anywhere in the system. I can post the .properties files if you need.

EDIT: Including a couple of log4j properties. These property files are same for all the other applications as well.

1st LOG file.

 # Define the root logger with appender file
  log=.//SI_AppLogs
  log4j.rootLogger=WARN, SomeApp

  log4j.logger.SomeAppLoggers = INFO, SomeApp     

 # Define the file appender
  log4j.appender.SomeApp=org.apache.log4j.DailyRollingFileAppender
  log4j.appender.SomeApp.File=${log}/CPEPortBasedAuthorization.log
  log4j.appender.SomeApp.DatePattern='.'yyyy-MM-dd
  log4j.appender.SomeApp.Append=true

  # Define the layout for file appender
  log4j.appender.SomeApp.layout=org.apache.log4j.PatternLayout
  log4j.appender.SomeApp.layout.conversionPattern=%d %-5r %-5p [%c] (%t:%x) %m%n

  log4j.additivity.org.apache=false
  log4j.additivity.SomeAppLoggers = false 

2nd Log file

 # Define the root logger with appender file


log=.//SI_AppLogs
  log4j.rootLogger=WARN, AnotherApp

  log4j.logger.AnotherAppLoggers = INFO, AnotherApp

  # Define the file appender
  log4j.appender.AnotherApp=org.apache.log4j.DailyRollingFileAppender
  log4j.appender.AnotherApp.File=${log}/CPEPortBasedAuthorization.log
  log4j.appender.AnotherApp.DatePattern='.'yyyy-MM-dd
  log4j.appender.AnotherApp.Append=true

  # Define the layout for file appender
  log4j.appender.AnotherApp.layout=org.apache.log4j.PatternLayout
  log4j.appender.AnotherApp.layout.conversionPattern=%d %-5r %-5p [%c] (%t:%x) %m%n

  log4j.additivity.org.apache=false
  log4j.additivity.AnotherAppLoggers = false 

Update:

I've not seen duplicate log4j.jars in the class path. I've ran the following code and verified.

String classpath = System.getProperty("java.class.path");

I've not seen any two log4j.properties files have the same Appender defined. Verified it by search the whole weblogic deploy directory.


Solution

  • It was a tough find for me as I have multiple applications in the VM. As per the article log4j jar file needs to be added to each application individually. Most of the classes in the log4j are singleton, so the root logger is getting created as a singleton for all the applications.(EAR applications). I've modified my application to have one jar per application, so far no issues.