Log4j configuration file interpretation and template page favorites

Source: Internet
Author: User

Recently, I am interested in the log configuration of log4j. After carefully studying it, I have a clear understanding of it. By the way, I have created a log file template for later viewing and using, by the way, I also provided some detailed and simple information for those who viewed log files in the cloud.

  

# Configure the overall Log Level and output purpose: note that the overall log level will overwrite the respective log levels of the output destination below, I set it to null and Log Level Controlled by each sub-item # A1 A2 is the name of the output destination respectively: I set A1 to console print A2 set to record the log to the file log4j. rootlogger =, a1, a2 # detailed configuration output by a1 leleappender outputs log4j for the console. appender. a1 = org. apache. log4j. consoleappender # threshold attribute) log4j output is not allowed for logs with lower levels than rootlogger logs. appender. a1.threshold = info # layout is clearly the meaning of layout. patternlayout is the layout mode log4j that can flexibly specify the output format. appender. a1.layout = org. apache. log4j. patternlayout # specify how to format the conversionpattern attribute: % d is the time output, you can specify the # % P output log level, that is, debug, info, warn, error .. one of the categories of # % C output log information is usually the full name of the class, such as Org. apache. log4j. logger; {2} limits the output directory % c {2} To log4j. logger # % F: name of the file where the output Log message is generated % L: row number in the output Code, for example, test0815.java: 16 (16 is the row number) # % m indicates the output log Content. % N indicates the output line break and press Enter. The total output is as follows :****-**-****:**: ** warn mod1408.test0815 (test0815.java: 16)-This is warn log4j. appender. a1.layout. conversionpattern = % d {yyyy-mm-dd hh: mm: SS} % P % c {2} (% F: % L) -% m % N # A2 output setting dailyrollingfileappender (and a log file generated every day) log4j. appender. a2 = org. apache. log4j. dailyrollingfileappender # location and file name of the log file log4j. appender. a2.file = D :\\ forwork \ logs \ log4j. loglog4j. appender. a2.threshold = warn # append attribute: The default value is true. To add a message to a specified file, false indicates that the message overwrites the specified file content log4j. appender. a2.append = true # immediateflush = true: the default value is true, meaning that all messages will be output to log4j immediately. appender. a2.immediateflush = truelog4j. appender. a2.layout = org. apache. log4j. patternlayoutlog4j. appender. a2.layout. conversionpattern = % d {yyyy-mm-dd hh: mm: SS} % P % c {2} (% F: % L) % 1x-% m % N # frequency setting of datepattern to update logs. Below is a log file updated every day, named log4j. log. ****-**-**. log, used as the file for storing historical logs # Set log4j. the log file is always the new log log4j stored on the current day. appender. a2.datepattern = '. 'yyyy-mm-dd '. log' # output Org. apache. debug-level logs generated by the ibatis class log4j.logger.org. apache. ibatis = debug # Java. debug-level information generated by SQL and subclass log4j. logger. java. SQL = debug # output Org. the warn level information generated by springframework classes and subclasses log4j.logger.org. springframework = warn # print logs of other frameworks to find relevant documents

 

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.