log4j配置实例:
[code="xml"]
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
<!-- ===================================================================== -->
<!-- -->
<!-- Log4j Configuration -->
<!-- -->
<!-- ===================================================================== -->
<!--
| For more configuration infromation and examples see the Jakarta Log4j
| owebsite: http://jakarta.apache.org/log4j
-->
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/" debug="false">
<!-- ================================= -->
<!-- Preserve messages in a local file -->
<!-- ================================= -->
<!-- A time/date based rolling appender -->
<appender name="FILE" class="org.jboss.logging.appender.DailyRollingFileAppender">
<errorHandler class="org.jboss.logging.util.OnlyOnceErrorHandler"/>
<param name="File" value="${jboss.server.home.dir}/log/server.log"/>
<param name="Append" value="true"/>
<param name="Threshold" value="INFO"/>
<param name="DatePattern" value="'.'yyyy-MM-dd"/>
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d %-5p [%c] %m%n"/>
</layout>
</appender>
<!-- 预警转存 -->
<appender name="ArticleTransfer" class="org.jboss.logging.appender.DailyRollingFileAppender">
<errorHandler class="org.jboss.logging.util.OnlyOnceErrorHandler"/>
<param name="File" value="${jboss.server.home.dir}/log/transfer.log"/>
<param name="Append" value="true"/>
<param name="Threshold" value="INFO"/>
<param name="DatePattern" value="'.'yyyy-MM-dd"/>
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d %-5p [%c] %m%n"/>
</layout>
</appender>
<!-- 历史转存 -->
<appender name="OriginalArticleTransfer" class="org.jboss.logging.appender.DailyRollingFileAppender">
<errorHandler class="org.jboss.logging.util.OnlyOnceErrorHandler"/>
<param name="File" value="${jboss.server.home.dir}/log/original_transfer.log"/>
<param name="Append" value="true"/>
<param name="Threshold" value="INFO"/>
<param name="DatePattern" value="'.'yyyy-MM-dd"/>
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d %-5p [%c] %m%n"/>
</layout>
</appender>
<!-- 取证快照 -->
<appender name="Evidence" class="org.jboss.logging.appender.DailyRollingFileAppender">
<errorHandler class="org.jboss.logging.util.OnlyOnceErrorHandler"/>
<param name="File" value="${jboss.server.home.dir}/log/evidence.log"/>
<param name="Append" value="true"/>
<param name="Threshold" value="INFO"/>
<param name="DatePattern" value="'.'yyyy-MM-dd"/>
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d %-5p [%c] %m%n"/>
</layout>
</appender>
<!-- 网站抽取投放 -->
<appender name="SiteExtractThrow" class="org.jboss.logging.appender.DailyRollingFileAppender">
<errorHandler class="org.jboss.logging.util.OnlyOnceErrorHandler"/>
<param name="File" value="${jboss.server.home.dir}/log/site_extract_throw.log"/>
<param name="Append" value="true"/>
<param name="Threshold" value="INFO"/>
<param name="DatePattern" value="'.'yyyy-MM-dd"/>
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d %-5p [%c] %m%n"/>
</layout>
</appender>
<!-- 网站新发现 -->
<appender name="SiteSearchEngine" class="org.jboss.logging.appender.DailyRollingFileAppender">
<errorHandler class="org.jboss.logging.util.OnlyOnceErrorHandler"/>
<param name="File" value="${jboss.server.home.dir}/log/site_search_engine.log"/>
<param name="Append" value="true"/>
<param name="Threshold" value="INFO"/>
<param name="DatePattern" value="'.'yyyy-MM-dd"/>
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d %-5p [%c] %m%n"/>
</layout>
</appender>
<!-- 新网站解析 -->
<appender name="SiteParseEngine" class="org.jboss.logging.appender.DailyRollingFileAppender">
<errorHandler class="org.jboss.logging.util.OnlyOnceErrorHandler"/>
<param name="File" value="${jboss.server.home.dir}/log/site_parse_engine.log"/>
<param name="Append" value="true"/>
<param name="Threshold" value="INFO"/>
<param name="DatePattern" value="'.'yyyy-MM-dd"/>
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d %-5p [%c] %m%n"/>
</layout>
</appender>
<!-- 网站有效性验证 -->
<appender name="SiteVal" class="org.jboss.logging.appender.DailyRollingFileAppender">
<errorHandler class="org.jboss.logging.util.OnlyOnceErrorHandler"/>
<param name="File" value="${jboss.server.home.dir}/log/site_val.log"/>
<param name="Append" value="true"/>
<param name="Threshold" value="INFO"/>
<param name="DatePattern" value="'.'yyyy-MM-dd"/>
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d %-5p [%c] %m%n"/>
</layout>
</appender>
<!-- 网站定期复核 -->
<appender name="PeriodicReview" class="org.jboss.logging.appender.DailyRollingFileAppender">
<errorHandler class="org.jboss.logging.util.OnlyOnceErrorHandler"/>
<param name="File" value="${jboss.server.home.dir}/log/site_periodicReview.log"/>
<param name="Append" value="true"/>
<param name="Threshold" value="INFO"/>
<param name="DatePattern" value="'.'yyyy-MM-dd"/>
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d %-5p [%c] %m%n"/>
</layout>
</appender>
<!-- 预警文章去重 -->
<appender name="HandleRepeat" class="org.jboss.logging.appender.DailyRollingFileAppender">
<errorHandler class="org.jboss.logging.util.OnlyOnceErrorHandler"/>
<param name="File" value="${jboss.server.home.dir}/log/handle_repeat.log"/>
<param name="Append" value="true"/>
<param name="Threshold" value="INFO"/>
<param name="DatePattern" value="'.'yyyy-MM-dd"/>
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d %-5p [%c] %m%n"/>
</layout>
</appender>
<!-- ============================== -->
<!-- Append messages to the console -->
<!-- ============================== -->
<appender name="CONSOLE" class="org.apache.log4j.ConsoleAppender">
<errorHandler class="org.jboss.logging.util.OnlyOnceErrorHandler"/>
<param name="Target" value="System.out"/>
<param name="Threshold" value="DEBUG"/>
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d{ABSOLUTE} %-5p [%c{1}] %m%n"/>
</layout>
</appender>
<!-- ================ -->
<!-- Limit categories -->
<!-- ================ -->
<!-- Limit the org.apache category to INFO as its DEBUG is verbose -->
<category name="org.apache">
<priority value="INFO"/>
</category>
<!-- Limit the org.jgroups category to WARN as its INFO is verbose -->
<category name="org.jgroups">
<priority value="WARN"/>
</category>
<!-- Limit jboss axis to INFO as its DEBUG is even more verbose -->
<category name="org.jboss.axis">
<priority value="INFO"/>
</category>
<!-- Limit the JSR77 categories -->
<category name="org.jboss.management">
<priority value="INFO"/>
</category>
<!-- ======================= -->
<!-- Setup the Root category -->
<!-- ======================= -->
<category name="cn.ipms.spider.evidence" additivity="false">
<priority value="INFO" />
<appender-ref ref="Evidence"/>
<appender-ref ref="CONSOLE"/>
</category>
<category name="cn.ipms.datacenter.site.spider" additivity="false">
<priority value="INFO" />
<appender-ref ref="SiteExtractThrow"/>
<appender-ref ref="CONSOLE"/>
</category>
<category name="cn.ipms.supervise.article.service.impl.AlarmArticleTransferServiceImpl" additivity="false">
<priority value="INFO" />
<appender-ref ref="ArticleTransfer"/>
<appender-ref ref="CONSOLE"/>
</category>
<category name="cn.ipms.supervise.article.service.impl.OriginalArticleTransferServiceImpl" additivity="false">
<priority value="INFO" />
<appender-ref ref="OriginalArticleTransfer"/>
<appender-ref ref="CONSOLE"/>
</category>
<category name="cn.ipms.datacenter.site.auto.ipml.WebsiteSearchEngineImpl" additivity="false">
<priority value="INFO" />
<appender-ref ref="SiteSearchEngine"/>
<appender-ref ref="CONSOLE"/>
</category>
<category name="cn.ipms.datacenter.site.auto.ipml.WebsiteParseEngineImpl" additivity="false">
<priority value="INFO" />
<appender-ref ref="SiteParseEngine"/>
<appender-ref ref="CONSOLE"/>
</category>
<category name="cn.ipms.datacenter.site.val.service.impl.SiteValServiceImpl" additivity="false">
<priority value="INFO" />
<appender-ref ref="SiteVal"/>
<appender-ref ref="CONSOLE"/>
</category>
<category name="cn.ipms.datacenter.site.review.service.impl.PeriodicReviewServiceImpl" additivity="false">
<priority value="INFO" />
<appender-ref ref="PeriodicReview"/>
<appender-ref ref="CONSOLE"/>
</category>
<category name="cn.ipms.supervise.article.engine.impl.HandleRepeatEngineImpl" additivity="false">
<priority value="INFO" />
<appender-ref ref="HandleRepeat"/>
<appender-ref ref="CONSOLE"/>
</category>
<!-- for ibatsi sql -->
<category name="com.ibatis.common.jdbc.ScriptRunner" additivity="false">
<priority value="debug"/>
</category>
<category name="com.ibatis.sqlmap.engine.impl.SqlMapClientDelegate" additivity="false">
<priority value="debug"/>
</category>
<category name="java.sql.Connection">
<priority value="debug"/>
</category>
<category name="java.sql.Statement">
<priority value="debug"/>
</category>
<category name="java.sql.PreparedStatement">
<priority value="debug"/>
</category>
<category name="java.sql.ResultSet">
<priority value="debug"/>
</category>
<!-- for ibatsi sql end-->
<root>
<appender-ref ref="CONSOLE"/>
<appender-ref ref="FILE"/>
</root>
</log4j:configuration>