Log4j configuration Template

Source: Internet
Author: User
<? XML version = "1.0" encoding = "UTF-8"?> <! Doctype log4j: Configuration System "log4j. DTD"> <log4j: configuration xmlns: log4j = "http://jakarta.apache.org/log4j/" DEBUG = "false"> <! -- Output mode: output to the console --> <appender name = "myconsole" class = "org. Apache. log4j. leleappender"> <! -- Set the channel name and output mode. There are 5 types of output mode appender: Org. apache. log4j. rollingfileappender Org. apache. log4j. consoleappender (console) Org. apache. log4j. fileappender (File) Org. apache. log4j. dailyrollingfileappender (a log file is generated every day) Org. apache. log4j. writerappender (send log information to a specified place in stream format) --> <Param name = "target" value = "system. out "/> <Param name =" threshold "value =" info "/> <! -- Threshold is a global filter that does not display information lower than the configured level. --> <! -- Set the log output format --> <layout class = "org. Apache. log4j. patternlayout"> <! -- Parameters start with % and different parameters indicate different formatting information: % C output full name of the class, which can be changed to % d {num }, the output range of the num class name is as follows: "org. apache. elattings. classname ", % c {2} Will output elattings. classname % d: the log output time is in the format of % d {yyyy-mm-dd hh: mm: SS, SSS}. You can specify the format, for example, % d {hh: mm: SS} % L location of log event output, including category name and thread, number of lines in the code % N linefeed % m output code specified information, such as Info ("message "), output Message % P output priority, namely fatal, error, etc. % R output the number of milliseconds from startup to display this log information % t output the thread name that generates this log event --> <! -- The default pattern: date priority [category] Message \ n --> <Param name = "conversionpattern" value = "% d {absolute} %-5 p [% c {1}] % m % N "/> </layout> </appender> <! -- The output method is: one log file every day --> <! -- Set the channel name to file. The output method is dailyrollingfileappender --> <appender name = "myfile" class = "org. Apache. log4j. dailyrollingfileappender"> <! -- Log file path and file name --> <! -- Add ../to logs, add/to drive C, not to bin directory --> <! -- If the system variable is set during loading. setproperty ("webapp", approot), where $ {webapp} --> <Param name = "file" value = ".. /logs/mylog. log "/> <! -- Set whether to add new logs to the base of the original log when the service is restarted --> <Param name = "APPEND" value = "true"/> <! -- Rolover at midnight each day --> <! -- E.g. mylog. log.2009-11-25.log --> <Param name = "datepattern" value = "'. 'yyyy-mm-dd'. log'"/> <! -- Rolover at the top of each hour <Param name = "datepattern" value = "'. 'yyyy-mm-dd-hh '. log' "/> --> <layout class =" org. apache. log4j. patternlayout "> <! -- The default pattern: date priority [category] Message \ n --> <Param name = "conversionpattern" value = "% d %-5 p [% C] % m % N"/> <! -- The full pattern: Date MS priority [category] (thread: NDC) Message \ n --> <! -- <Param name = "conversionpattern" value = "% d %-5R %-5 p [% C] (% T: % x) % m % N "/> --> </layout> </appender> <appender name =" error_log "class =" org. apache. log4j. dailyrollingfileappender "> <errorhandler class =" org. apache. log4j. helpers. onlyonceerrorhandler "/> <Param name =" file "value =" error. log "/> <Param name =" APPEND "value =" true "/> <! -- Specify the log output level --> <Param name = "threshold" value = "info"/> <Param name = "datepattern" value = "'. 'yyyy-mm-dd '. log' "/> <layout class =" org. apache. log4j. patternlayout "> <Param name =" conversionpattern "value =" % d %-5 p [% C] % m % N "/> </layout> </appender> <! -- Level: indicates the priority of the log. The priority ranges from high to low and is divided into off, fatal, error, warn, info, debug, and all. Log4j only supports four levels: fatal, error, warn, info, and debug. --> <! -- Specify logger settings. additiger indicates whether to overwrite the output log. If it is false, logs in dserrorlog logger will not be output by other logger (such as root) that meet the conditions --> <! -- Output the logger named dserrorlog to the appender of "eeror_log". The so-called logger name is: when the logger is defined, the logger log parameter of the constructor is logger. getlogger ("dserrorlog"); --> <logger name = "dserrorlog" additi.pdf = "false"> <level class = "org. apache. log4j. level "value =" debug "/> <appender-ref =" error_log "/> </logger> <! -- Output the logs in the specified class package. For example, to output the SQL statement generated during hibernate running, you can set it as follows --> <category name = "org. hibernate. SQL "> <priority value =" debug "/> <! -- If an appender is specified, these logs will be output to the specified appender, for example: <appender-ref = "myfile"/> otherwise, all appender --> </Category> <! -- By default, the root will be automatically built to output Info-level logs to the console, for logger inheritance --> <root> <priority value = "info"/> <appender-ref = "myconsole"/> <appender-ref = "myfile"/> </root> </log4j: configuration>

<?xml version="1.0" encoding="UTF-8" ?><!DOCTYPE log4j:configuration SYSTEM "log4j.dtd"><log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/"><appender name="CONSOLE" class="org.apache.log4j.ConsoleAppender"><param name="Target" value="System.out" /><layout class="org.apache.log4j.PatternLayout"><param name="ConversionPattern"value="$time=[%d{dd MMM yyyy HH:mm:ss,SSS}] $thread=[%t] $call=%C.%M(%F:%L) $level=%-5p $msg=%m%n" /></layout></appender><appender name="ROLL" class="org.apache.log4j.RollingFileAppender"><param name="File" value="logs/all.log" /><param name="Append" value="true" /><param name="Encoding" value="UTF-8" /><param name="MaxBackupIndex" value="100" /><param name="MaxFileSize" value="5MB" /><layout class="org.apache.log4j.PatternLayout"><param name="ConversionPattern"value="$time=[%d{dd MMM yyyy HH:mm:ss,SSS}] $thread=[%t] $call=%C.%M(%F:%L) $level=%-5p $msg=%m%n" /></layout></appender><appender name="ERRORROLL" class="org.apache.log4j.RollingFileAppender"><param name="File" value="logs/error.log" /><param name="Append" value="true" /><param name="Encoding" value="UTF-8" /><param name="Threshold" value="ERROR" /><param name="MaxBackupIndex" value="100" /><param name="MaxFileSize" value="5MB" /><layout class="org.apache.log4j.PatternLayout"><param name="ConversionPattern"value="$time=[%d{dd MMM yyyy HH:mm:ss,SSS}] $thread=[%t] $call=%C.%M(%F:%L) $level=%-5p $msg=%m%n" /></layout></appender><root><priority value="debug" /><appender-ref ref="CONSOLE" /><appender-ref ref="ROLL" /><appender-ref ref="ERRORROLL" /></root></log4j:configuration>

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.