Using Log4J in James

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

Change the SAR-INF/environment.xml.


  <logs version="1.1">

Log4J Enabled:

  <logs version="log4j" xmlns:log4j="" debug="false">

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

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

  <logs version="log4j" xmlns: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"/>

          <!-- 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"/>

          <!-- CATEGORIES -->

          <category name="smtpserver">
            <priority value="INFO"/>
          <category name="spoolmanager">
            <priority value="INFO"/>
          <category name="James.Mailet">
            <priority value="INFO"/>
          <!-- Do not show INFO about Apache utilities -->
          <category name="org.apache">
            <priority value="WARN"/>
          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 -->

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


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:

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