How to use Log4J instead of Avalon Logkit for Cocoon

This is written based on the 2.1.6-DEV version in SVN at 2004/10/13, so things might be different before or after this version.

1. add this to web.xml or, if it is already in comments, uncomment it:

  <init-param>
        <param-name>logger-class</param-name>
        <param-value>org.apache.avalon.excalibur.logger.Log4J!LoggerManager</param-value>
  </init-param>

2. add log4j.jar in WEB-INF/lib if needed

3. create WEB-INF/classes/log4j.properties to setup logging, or uncomment the following lines in web.xml to define the location of log4j.xconf (i.e. the XML version of the log4j.properties file). A sample log4j.xconf is already provided in WEB-INF.

      <init-param>
        <param-name>log4j-config</param-name>
        <param-value>/WEB-INF/log4j.xconf</param-value>
      </init-param>

4. (added by BertrandDelacretaz:) Another useful logging trick is to use log4j for the output of ant as well, by setting these options on the ant command line:

   -listener org.apache.tools.ant.listener.Log4jListener
   -Dlog4j.configuration=file:/path-to-log4j-config

This is very useful for crazy folk like me who start their production systems via ant ;-)

Note: Make sure the path to the logfile exists. Log4J can create a non-existing file, but not non-existing directories!

CocoonLog4J (last edited 2009-09-20 23:40:24 by localhost)