Differences between revisions 1 and 2
Revision 1 as of 2006-08-27 11:41:11
Size: 2867
Comment: Using Log4J in Apache James
Revision 2 as of 2009-09-20 22:58:41
Size: 2869
Editor: localhost
Comment: converted to 1.6 markup
Deletions are marked like this. Additions are marked like this.
Line 98: Line 98:
[http://svn.apache.org/repos/asf/avalon/cvs-migration-snapshot/avalon-phoenix/src/java/org/apache/avalon/phoenix/components/logger/DefaultLogManager.java] [[http://svn.apache.org/repos/asf/avalon/cvs-migration-snapshot/avalon-phoenix/src/java/org/apache/avalon/phoenix/components/logger/DefaultLogManager.java]]

Using Log4J in James


The use is relatively easy (probed in James 2.3.0rc1)

Change the SAR-INF/environment.xml.

Original:

  <logs version="1.1">

Log4J Enabled:

  <logs version="log4j" xmlns:log4j="http://jakarta.apache.org/log4j/" debug="false">

Now... configure the log4j appenders, targets, etc... example:

<?xml version="1.0"?>
<!-- Example SAR-INF/environment.xml -->

<server>
  <logs version="log4j" xmlns:log4j="http://jakarta.apache.org/log4j/" debug="false">

          <!-- Send only error messages to stdout -->
          <appender name="STDOUT" class="org.apache.log4j.ConsoleAppender">
            <param name="Threshold" value="ERROR"/>
            <layout class="org.apache.log4j.PatternLayout">
              <param name="ConversionPattern" value="%d %-5p [%t] %C{2} (%F:%L) - %m%n"/>
            </layout>
          </appender>

          <!-- Log messages to a file and rotate it everyday at midnight -->
          <appender name="DATE_LOGFILE" class="org.apache.log4j.DailyRollingFileAppender">
            <param name="File" value="${phoenix.home}/logs/james.log"/>
            <param name="Append" value="true"/>
            <!-- Rollover at midnight each day -->
            <param name="DatePattern" value="'.'yyyy-MM-dd"/>
            <!-- Message layout format -->
            <layout class="org.apache.log4j.PatternLayout">
              <param name="ConversionPattern" value="%d %-5p [%c] %m%n"/>
            </layout>
          </appender>

          <!-- CATEGORIES -->

          <category name="smtpserver">
            <priority value="INFO"/>
          </category>
          <category name="spoolmanager">
            <priority value="INFO"/>
          </category>
          <category name="James.Mailet">
            <priority value="INFO"/>
          </category>
          <!-- Do not show INFO about Apache utilities -->
          <category name="org.apache">
            <priority value="WARN"/>
          </category>
          <!--
          Some categories to choose :
            James.Mailet, James, spoolmanager, dnsserver,
            remotemanager, pop3server, smtpserver, nntpserver,
            nntp-repository, mailstore, users-store, objectstorage,
            connections, sockets, scheduler, fetchpop, fetchmail, ...
          -->

          <!-- ROOT CATEGORY -->

          <root>
            <priority value="DEBUG"/>
            <appender-ref ref="DATE_LOGFILE"/>
            <appender-ref ref="STDOUT" />
          </root>

  </logs>
</server>

And if you want that processor XML can validate the configuration file you do not forget to extract the file log4j.dtd of jar (log4j-1.2.13.jar) and to place it in directory SAR-INF/

Now you will have to add the following line in the beginning of the file SAR-INF/environment.xml

<?xml version="1.0"?>
<!-- For validate XML -->
<!DOCTYPE logs SYSTEM "log4j.dtd">

see also: http://svn.apache.org/repos/asf/avalon/cvs-migration-snapshot/avalon-phoenix/src/java/org/apache/avalon/phoenix/components/logger/DefaultLogManager.java

log4j (last edited 2009-09-20 22:58:41 by localhost)