log4j config sample -- display log both to log file and console

<?xml version="1.0" ?>

<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">

<log4j:configuration xmlns:log4j='http://jakarta.apache.org/log4j/'>

  <!-- ==application log file====================================== -->

      <appender name="appLogFile" class="org.apache.log4j.RollingFileAppender">

            <param name="File" value="./log/marketDataDetector.log" />

            <param name="Append" value="true" />

            <param name="MaxFileSize" value="5MB" />

            <param name="MaxBackupIndex" value="20" />

            <layout class="org.apache.log4j.PatternLayout">

                  <param name="ConversionPattern" value="%d{HH:mm:ss.SSS} - %p - %r - %.30c - %m%n" />

            </layout>

      </appender>

     

      <appender name="console" class="org.apache.log4j.ConsoleAppender">

      <layout class="org.apache.log4j.PatternLayout">

                  <param name="ConversionPattern" value="%d{yyyy-MM-dd HH:mm:ss.SSS z} - %p - %t - %.30c - %m%n"/>

      </layout>

      </appender>

  <!-- ============================================================= -->

      <root>

            <priority value="DEBUG" />

            <appender-ref ref="appLogFile" />

            <appender-ref ref="console" />

      </root>

</log4j:configuration>

你可能感兴趣的:(apache,log4j,xml)