You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4j-user@logging.apache.org by "Doubleday, Dennis" <dd...@vocollect.com> on 2003/10/16 21:10:32 UTC

App-server independent log4j logging

My application needs to be deployable to both JBoss and Websphere (and
possibly Weblogic in future). I am trying to use log4j in my app, but not
having any success, even only with JBoss.

Here's the deal--I want to include my own log4j.jar and log4j.xml in my WAR
file. If the app server is using log4j itself, as JBoss does, my log4j.xml
should only extend the configuration set up by JBoss. I don't want to add my
Appenders to the JBoss log4j.xml, I want them in my WAR so it doesn't depend
on the JBoss environment.

Here is a snippet of what I am doing in my init servlet:

        String prefix =  getServletContext().getRealPath("/");
        String filePath = prefix + fileName;

        System.out.println
           ("Log4JConfigServlet - initializing log4j using file: " +
filePath);
        
        try {
            if (fileName.indexOf("xml") != -1) {
                DOMConfigurator.configure(filePath);
            } else {
                PropertyConfigurator.configure(filePath);
            }
            
           Logger log = Logger.getLogger(Log4JConfigServlet.class);
           if (log.isInfoEnabled()) {
               log.info("Log4j initilized.");
           }
           
        } catch (Exception e) {

I see both the println and the initial INFO log message in the JBoss console
log, but the two FILE appenders don't seem to be getting created--I see
debug output from the initial JBoss configuration but there is no debug
output when my config file is processed. (The full file is at the end of the
message).

This approach worked in JBoss 3.0.6 but it mysteriously stopped when I
upgraded to JBoss 3.2.1.

Here's my log4j.xml:

<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/"
debug="true">

  <!-- ================================= -->
  <!-- Preserve messages in a local file -->
  <!-- ================================= -->

  <!-- A size based file rolling appender -->
  <appender name="FALCONFILE" class="org.apache.log4j.RollingFileAppender">
    <param name="File" value="Falcon.log"/>
    <param name="Append" value="false"/>
    <param name="MaxFileSize" value="500KB"/>
    <param name="MaxBackupIndex" value="20"/>

    <layout class="org.apache.log4j.PatternLayout">
      <param name="ConversionPattern" value="%d %-5p [%c{1}.%M] %m%n"/>
    </layout>	    
  </appender>

  <appender name="FALCONHTML" class="org.apache.log4j.RollingFileAppender">
    <param name="File" value="Falcon.html"/>
    <param name="Append" value="false"/>
    <param name="MaxFileSize" value="500KB"/>
    <param name="MaxBackupIndex" value="20"/>
    <param name="threshold" value="info"/>
    
    <layout class="org.apache.log4j.HTMLLayout"/>
    
  </appender>

  <appender name="FALCONCONSOLE" class="org.apache.log4j.ConsoleAppender">
    <param name="Target" value="System.out"/>

    <layout class="org.apache.log4j.PatternLayout">
      <!-- The default pattern: Date Priority [Category] Message\n -->
      <param name="ConversionPattern" value="%-5p [%c{1}] %m%n"/>
    </layout>
  </appender>

  <!-- Falcon base logger -->
  <logger name="com.vocollect">
    <level value="debug" />
    <appender-ref ref="FALCONFILE" />
    <appender-ref ref="FALCONHTML" />
  </logger>

</log4j:configuration>

---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: log4j-user-help@jakarta.apache.org