log4j configuration File Detailed explanation

Source: Internet
Author: User

explanation of the statements in the Log4j.properties file
1 This sentence is the output of the log information of level info to stdout and R, the definition of stdout and r in the following code, can be arbitrarily named. Level can be divided into off, FATAL, error, WARN, INFO, DEBUG, all, if the configuration off does not play any information, if configured as info so only display info, WARN, error log information, and DEBUG information will not be displayed, Refer to the third section to define the logger in the configuration file. 2 3 Log4j.rootcategory=info,stdout4 5 6 This sentence defines what type of output is named stdout, which can be7 Org.apache.log4j.ConsoleAppender (console),8 org.apache.log4j.FileAppender (file),9 org.apache.log4j.DailyRollingFileAppender (generates a log file every day),Ten Org.apache.log4j.RollingFileAppender (creates a new file when the file size reaches the specified size) One Org.apache.log4j.WriterAppender (send log information in stream format to any specified location) A refer to the third section to define the Appender in the configuration file.  -  - Log4j.appender.stdout=org.apache.log4j.consoleappender the #log4j. Appender.r=org.apache.log4j.dailyrollingfileappender - #log4j. Appender.r.file=/data/logs/nmc/txp-log -  -   +  -  + This sentence is the type of layout that defines the output named stdout, which can be A org.apache.log4j.HTMLLayout (Layout in HTML table Form), at Org.apache.log4j.PatternLayout (flexibility to specify layout mode), - Org.apache.log4j.SimpleLayout (contains the level of log information and the information string), - Org.apache.log4j.TTCCLayout (contains information about the time, thread, category, etc.) of the log - refer to the third section to define layout in the configuration file.  -  - Log4j.appender.stdout.layout=org.apache.log4j.patternlayout in #log4j. Appender.r.layout=org.apache.log4j.patternlayout -  to  + If you use the pattern layout to specify the exact format of the printed information Conversionpattern, print the parameters as follows: - %m The message specified in the output code; the %M Output The name of the method for printing the log; * %p output priority, i.e. debug,info,warn,error,fatal; $ %r Output The number of milliseconds that the log information is consumed from the application boot to output;Panax Notoginseng the class that the%c output belongs to, usually the full name of the class in which it is located; - %t Output The name of the thread that generated the log event; the %n output A carriage return newline character, the Windows platform is "RN", UNIX platform is "n"; + %d the date or time of the output log time, the default format is ISO8601, can also be specified after the format, such as:%d{yyyy-mm-dd hh:mm:ss,sss}, the output is similar to: 2002-10-18 22:10:28,921; A %l where the output log event occurs, and the number of rows in the code; the [QC] is the beginning of the log information, can be any character, generally referred to as the project abbreviation.  + the output information - [TS] DEBUG [main] Abstractbeanfactory.getbean (189) | Returning cached instance of singleton Bean ' myautoproxy ' $ refer to the third section to define the formatting log information in the configuration file.  $  - LOG4J.APPENDER.STDOUT.LAYOUT.CONVERSIONPATTERN=[%D{YYYY-MM-DD hh:mm:ss,sss}]**[%p]**[%t]**[%c{1}:%l]:%m%n  - #log4j. Appender.r.layout.conversionpattern=[%d{yyyy-mm-dd hh:mm:ss,sss}]**[%p]**[%t]**[%c{1}:%l]:%m%n the  - Wuyi Specifies the rank of all classes under the COM.OPENSYMPHONY.XWORK2 package as info the You can change the COM.OPENSYMPHONY.XWORK2 to the package name that you use for your project.  -  Wu Log4j.logger.com.opensymphony.xwork2=info - Log4j.logger.org.springframework=info About Log4j.logger.com.ibatis=info $ Log4j.logger.java.sql=info -  -  - It is the flag bit of whether the child logger inherits the output source (Appender) of the parent logger. Specifically, by default, logger inherits the Appender of the parent logger, which means that the logger is output in the logger of the parent appender. If Additivity is set to false, the child logger will only output in its own appender, not in the appender of the parent logger.  A log4j.logger.DALCompenent = info, Dallogappender + log4j.additivity.DALCompenent = False the Log4j.appender.dallogappender=org.apache.log4j.dailyrollingfileappender - Log4j.appender.dallogappender.file=/export/home/jboss-4.2.1.ga-nmc-txp/server/default/log/nmcdal.log $  the The default value is True, the message is added to the specified file, and false refers to overwriting the message with the specified file content.  the  the log4j.appender.dallogappender.append=true the   -  in specifies the lowest level of output for log messages.  the  the Log4j.appender.dallogappender.threshold=info About Log4j.appender.dallogappender.layout=org.apache.log4j.patternlayout thelog4j.appender.dallogappender.layout.conversionpattern=%d-%c-%-4r [%t]%-5p%x-%m%n
View Code

Log4j property Interpretation of the configuration file

I. Description of the meaning of the parameter
Types of output levels
ERROR, WARN, INFO, DEBUG
Error is a critical error, mainly a program
WARN for general warnings, such as session loss
Info is the general information to display, such as login log out
Debug information for the program


Configure log information Output destination
Log4j.appender.appenderName = Fully.qualified.name.of.appender.class
1.org.apache.log4j.consoleappender (console)
2.org.apache.log4j.fileappender (file)
3.org.apache.log4j.dailyrollingfileappender (Generate a log file every day)
4.org.apache.log4j.rollingfileappender (creates a new file when the file size reaches the specified size)
5.org.apache.log4j.writerappender (send log information in stream format to any specified location)


Configure the format of log information
log4j.appender.appenderName.layout = Fully.qualified.name.of.layout.class
1.org.apache.log4j.htmllayout (Layout in HTML table Form),
2.org.apache.log4j.patternlayout (flexibility to specify layout mode),
3.org.apache.log4j.simplelayout (contains the level of log information and the information string),
4.org.apache.log4j.ttcclayout (contains information about the time, thread, category, etc.) of the log

Console Options
threshold=debug: Specifies the lowest level of output for log messages.
immediateflush=true: The default value is true, meaning that all messages will be output immediately.
Target=system.err: By default: System.out, specify output console

Fileappender Options
threshold=debuf: Specifies the lowest level of output for log messages.
immediateflush=true: The default value is true, meaning that all messages will be output immediately.
file=mylog.txt: Specifies the message output to the Mylog.txt file.
Append=false: The default value is True, the message is added to the specified file, and false refers to overwriting the message with the specified file content.

Rollingfileappender Options
threshold=debug: Specifies the lowest level of output for log messages.
immediateflush=true: The default value is true, meaning that all messages will be output immediately.
file=mylog.txt: Specifies the message output to the Mylog.txt file.
Append=false: The default value is True, the message is added to the specified file, and false refers to overwriting the message with the specified file content.
maxfilesize=100kb: The suffix can be kb, MB, or GB. When the log file reaches this size, it will automatically scroll to move the original content to the Mylog.log.1 file.
maxbackupindex=2: Specifies the maximum number of scroll files that can be produced.
log4j.appender.a1.layout.conversionpattern=%-4r%-5p%d{yyyy-mm-dd HH:mm:ssS}%c%m%n


The meaning of several symbols in the log Information format:
- x: left-aligned when the information is output;
%p: Output log information priority, i.e. Debug,info,warn,error,fatal,
%d: The date or time of the output log time, the default format is ISO8601, can also be specified after the format, such as:%d{yyy MMM dd hh:mm:ss,sss}, output similar: October 18, 2002 22:10:28,921
%r: The number of milliseconds to output the log information from the application boot to output
%c: The class in which the output log information belongs, usually the full name of the class in which it is located
%t: Output The name of the thread that generated the log event
%l: The location of the output log event, which corresponds to the combination of%c.%m (%f:%l), including the class name, the thread that occurred, and the number of rows in the code. Example: Testlog4.main (testlog4.java:10)
%x: The NDC (nested diagnostic environment) associated with the output and current line threads, especially for multi-client multithreaded applications such as Java Servlets.
percent: Output a "%" character
%F: The name of the file where the output log message was generated
%l: Line numbers in the output code
%m: The specified message in the output code, resulting in the log specific information
%n: Output a carriage return line break, Windows platform is "\ r \ n", Unix platform for "\ n" Output log information line-wrapping
you can add modifiers between% and pattern characters to control their minimum width, maximum width, and text alignment. such as:
1)%20c: Specify the name of the output category, the minimum width is 20, if the category name is less than 20, the default is the right alignment.
2)%-20c: Specify the name of the output category, the minimum width is 20, if the category name is less than 20, the "-" number specifies left-aligned.
3)%.30c: Specify the name of the output category, the maximum width is 30, if the category name is greater than 30, will be the left more than the character of the cut off, but less than 30, there will be no spaces.
4)%20.30c: If the category name is less than 20, fill in the blanks, and right-aligned, if its name is longer than 30 characters, it is truncated from the far left character.

log4j configuration File Detailed explanation

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.