LOG4J (iv) XML form configuration file

Source: Internet
Author: User

Reference articles

http://willow-na.iteye.com/blog/347340

(1) configuration file

Here is the code that came directly from that article, made some changes, and will also fill in some other content, I hope the original author does not mind

<?XML version= "1.0" encoding= "UTF-8"?><!DOCTYPE log4j:configuration SYSTEM "Log4j.dtd">  <log4j:configurationxmlns:log4j= ' http://jakarta.apache.org/log4j/' >      <Appendername= "MyConsole"class= "Org.apache.log4j.ConsoleAppender">        <Layoutclass= "Org.apache.log4j.PatternLayout">             <paramname= "Conversionpattern"value= "[%d{dd hh:mm:ss,sss\}%-5p] [%t]%c{2\}-%m%n" />        </Layout>        <!--The filter sets the output level (Info-warn) and sets the Levelmin and Levelmax to the same value, enabling only one level of logging to be output -        <Filterclass= "Org.apache.log4j.varia.LevelRangeFilter">            <paramname= "Levelmin"value= "INFO" />            <paramname= "Levelmax"value= "WARN" />            <paramname= "Acceptonmatch"value= "true" />        </Filter>    </Appender>    <Appendername= "MyFile"class= "Org.apache.log4j.RollingFileAppender">          <paramname= "File"value= "D:/output.log" /><!--set Log output file path (including file name) -        <!--set whether new logs are appended to the original log when the service is restarted -        <paramname= "Append"value= "true" />        <paramname= "Maxbackupindex"value= "Ten" />        <Layoutclass= "Org.apache.log4j.PatternLayout">            <paramname= "Conversionpattern"value= "%p (%c:%l)-%m%n" />        </Layout>    </Appender> 
<!--configured for the log output form of a class-<Appendername= "Activexappender"class= "Org.apache.log4j.DailyRollingFileAppender"> <paramname= "File"value= "E:/activex.log" /> <paramname= "Datepattern"value= "'. ' Yyyy-mm-dd '. Log ' " /> <Layoutclass= "Org.apache.log4j.PatternLayout">    <paramname= "Conversionpattern"value= "[%d{mmdd HH:mm:ss sss\}%-5p] [%t]%c{3\}-%m%n" /> </Layout> </Appender> <!--a logger child element defines a log writer that specifies the settings of the logger, defines only one level of logging for a package or a class below it, additivity indicates whether to follow the default inheritance mechanism - <Loggername= "Com.runway.bssp.activeXdemo"additivity= "false"> < Priorityvalue= "Info"/> <Appender-refref= "Activexappender" /> </Logger> <!--settings for root logger - <Root> < Priorityvalue= "Debug"/> <Appender-refref= "MyConsole"/> <Appender-refref= "MyFile"/> </Root></log4j:configuration>

(2) Loading XML form configuration file in code

LOG4J (iv) XML form configuration file

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.