Appenders configuration of log4j, log4jappenders

Source: Internet
Author: User

Appenders configuration of log4j, log4jappenders

Because log4j was used at the beginning, many configuration items were not understood and recorded.

The following is a log4j. xml configuration file automatically generated by me when I create a Spring MVC project using STS (Spring Tool Suite.

 1 <?xml version="1.0" encoding="UTF-8"?> 2 <!DOCTYPE log4j:configuration PUBLIC "-//APACHE//DTD LOG4J 1.2//EN" "log4j.dtd"> 3 <log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/"> 4  5     <!-- Appenders --> 6     <appender name="console" class="org.apache.log4j.ConsoleAppender"> 7         <param name="Target" value="System.out" /> 8         <layout class="org.apache.log4j.PatternLayout"> 9             <param name="ConversionPattern" value="%-5p: %c - %m%n" />10         </layout>11     </appender>12     13     <!-- Application Loggers -->14     <logger name="com.shanshan.test">15         <level value="info" />16     </logger>17     18     <!-- 3rdparty Loggers -->19     <logger name="org.springframework.core">20         <level value="info" />21     </logger>22     23     <logger name="org.springframework.beans">24         <level value="info" />25     </logger>26     27     <logger name="org.springframework.context">28         <level value="info" />29     </logger>30 31     <logger name="org.springframework.web">32         <level value="info" />33     </logger>34 35     <!-- Root Logger -->36     <root>37         <priority value="warn" />38         <appender-ref ref="console" />39     </root>40     41 </log4j:configuration>

What I want to talk about is the configuration content in Appenders.

 

Output Mode:

Org. apache. log4j. leleappender Console
Org. apache. log4j. FileAppender File
Org. apache. log4j. DailyRollingFileAppender Generates a log file every day.
Org. apache. log4j. RollingFileAppender When the file size reaches the specified size, a new file is generated.
Org. apache. log4j. WriterAppender Send log information to any specified place in stream format

 

 

 

 

 

 

PatternLayout Configuration:

Configuration

Description Example  
% C The output category, usually the full name of the class. You can also include a decimal parameter to limit the output category level. By default, the entire category is output. % C Org. apache. log4j. PatternLayout  
% C {2} Log4j. PatternLayout  
% C The category of the class that calls the logger. You can also include a decimal parameter to limit the output category level. By default, the entire category is output. % C Org. apache. log4j. PatternLayout Processing is slow and you are cautious when using it.
% C {1} PatternLayout
% D The time when the log is output. The date format parameter can be followed. The default parameter encoding is ISO8601. For the date format, see SimpleDateFormat. % D 09:23:56, 561  
% D {yyyy-MM-dd HH: mm: ss SSS} 09:23:56 561  
% D {ABSOLUTE} 09:23:56, 561  
% D {DATE} 18 August 17 09:23:56, 561  
% D {ISO8601} 09:23:56, 561  
% F Display the name of the source file that calls logger   HomeController. java Processing is slow and you are cautious when using it.
% L Location where the output log event occurs, including the category name, the thread that occurs, and the number of lines in the code   Com. shanshan. bo. HomeController. border (HomeController. java: 155)  
% L Display the number of lines of code that call logger     Processing is slow and you are cautious when using it.
% M Output the specified information in the code      
% M Display the method name for calling logger   Main Processing is slow and you are cautious when using it.
% N Linefeed in the current system      
% P Displays the priority of the log.   INFO  
% R Displays the number of milliseconds that have elapsed since the program was started to record the log.      
% T Name of the thread that generates the log event   Tomcat-http -- 38  
% X Output logs in NDC (Nested Diagnostic Context, thread stack) Order      
% X Output logs by MDC (Mapped Diagnostic Context, thread ing table. It is usually used for connecting multiple clients to the same server. It is convenient for the server to distinguish the logs left by the client.      
% Output A percent sign      

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

General Format Configuration:

Configuration Alignment Mode Minimum Length Maximum length Description
% 20c Right 20   If the namespace length is less than 20, enter space on the left
%-20c Left 20   If the namespace length is less than 20, the right side is filled with spaces
%. 30c     30 If the namespace length exceeds 30, Remove extra characters
% Limit 30C Right 20 30 If the namespace length is less than 20, spaces are filled on the left. If the namespace length exceeds 30, extra characters are truncated.
%-Limit 30C Left 20 30 If the namespace length is less than 20, the right side is filled with spaces. If the namespace length exceeds 30, the excess characters are truncated.

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.