title: LOG4J as a singleton, anyway to avoid log4j logging conflicts in web environment
body: <p>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.</p>
  
  <p>This seems to cause issues with log4j.  Different webapps could have different log4j configurations but the logging will move to the same file.</p>
  
  <p>Reading online, it looks like log4j uses singletons a lot, in terms of the appenders and other functionality.</p>
  
  <p>Is there a way to completely separate the log4j configurations from one webapp from the other.</p>
  
  <p>Server: websphere6+<br>
  Log4j: 1.4.2<br>
  Java: 1.5</p>
  
  <pre><code>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
  </code></pre>
  
  <p>Right now, logging from webapp2 may appear in the webapp1 logs and vice verse.  We don't want that.</p>
  
  <p><strong>Possible Solution:</strong></p>
  
  <ul>
  <li><p>It might be possible to add a custom file appender?  Would that fix the issue and what code would I add to the custom appender?</p></li>
  <li><p>Is it possible to change the log4j initialization.  E.g., could I use some startup servlet to load logj4 for each webapp.</p></li>
  </ul>