log4j the format meaning of the Conversionpattern parameter-go

Source: Internet
Author: User

Transferred from: http://www.blogjava.net/wilesun/archive/2007/10/30/156999.html

LOG4J recommends using only four levels, with priority levels from high to low, error, WARN, INFO, DEBUG
#这里定义能显示到的最低级别, if you define to the info level, you will not see the debug level of information!
Log4j.rootlogger=debug

#将DAO层log记录到DAOLog, in Alllog
Log4j.logger.dao=debug,a2,a4
#将逻辑层log记录到BusinessLog, in Alllog
Log4j.logger.businesslog=debug,a3,a4

#A1--Print to the screen
Log4j.appender.a1=org.apache.log4j.consoleappender
Log4j.appender.a1.layout=org.apache.log4j.patternlayout
log4j.appender.a1.layout.conversionpattern=%-5p [%t]%37c%3x-%m%n

#A2--Print to file Daolog--specifically for DAO layer service
Log4j.appender.a2=org.apache.log4j.dailyrollingfileappender
Log4j.appender.a2.file=daolog
Log4j.appender.a2.datepattern= '. ' Yyyy-mm-dd
Log4j.appender.a2.layout=org.apache.log4j.patternlayout
LOG4J.APPENDER.A2.LAYOUT.CONVERSIONPATTERN=[%-5P]%d{yyyy-mm-dd Hh:mm:ss,sss} method:%l%n%m%n

#A3--Print to file Businesslog--specifically record the logical processing layer service log information
Log4j.appender.a3=org.apache.log4j.dailyrollingfileappender
Log4j.appender.a3.file=businesslog
Log4j.appender.a3.datepattern= '. ' Yyyy-mm-dd
Log4j.appender.a3.layout=org.apache.log4j.patternlayout
LOG4J.APPENDER.A3.LAYOUT.CONVERSIONPATTERN=[%-5P]%d{yyyy-mm-dd Hh:mm:ss,sss} method:%l%n%m%n

#A4--Print to file Alllog--Log all log information
Log4j.appender.a4=org.apache.log4j.dailyrollingfileappender
Log4j.appender.a4.file=alllog
Log4j.appender.a4.datepattern= '. ' Yyyy-mm-dd
Log4j.appender.a4.layout=org.apache.log4j.patternlayout
LOG4J.APPENDER.A4.LAYOUT.CONVERSIONPATTERN=[%-5P]%d{yyyy-mm-dd Hh:mm:ss,sss} method:%l%n%m%n

#Appender的使用
Log4j.appender.a2=org.apache.log4j.dailyrollingfileappender
Log4j.appender.a2.file=demo
Log4j.appender.a2.datepattern= '. ' Yyyy-mm-dd
Log4j.appender.a2.layout=org.apache.log4j.patternlayout
log4j.appender.a2.layout.conversionpattern=%m%n

#Layout的配置
Log4j.appender.a2.layout=org.apache.log4j.patternlayout
LOG4J.APPENDER.A2.LAYOUT.CONVERSIONPATTERN=[%-5P]%d{yyyy-mm-dd Hh:mm:ss,sss} method:%l%n%m%n

The format meaning of the Conversionpattern parameter
Format name meaning
The full name of the class to which the%c output log information belongs
%d the date or time of the output log time, the default format is ISO8601, or the format can be specified later, for example:%d{yyy-mm-dd HH:mm:ss}, output similar to: 2002-10-18-22:10:28
%f the class name of the class to which the output log information belongs
%l the occurrence of the output log event where the statement that outputs the log information is in the first line of the class it is in
%m the information specified in the output code, such as a message in log (message)
%n output a carriage return newline character, Windows platform is "RN", UNIX platform is "n"
%p output priority, or debug,info,warn,error,fatal. Debug if the debug () output is called, and so on
%r the number of milliseconds that the output from the application starts to output this log information
%t output The name of the thread that generated the log event

The #1 defines two outputs
Log4j.rootlogger = INFO, A1, A2,A3

#2 define A1 output to the controller
Log4j.appender.A1 = Org.apache.log4j.ConsoleAppender
The layout mode for the #3 definition A1 is patternlayout
Log4j.appender.A1.layout = Org.apache.log4j.PatternLayout
#4 defining the output format of the A1
Log4j.appender.A1.layout.ConversionPattern =%-4r [%t]%-5p%c-%m%n

#5 define A2 output to a file
Log4j.appender.A2 = Org.apache.log4j.RollingFileAppender
#6 define A2 to which file to output
Log4j.appender.A2.File = F:nepalonclassesexample3.log
#7 defines the maximum length of the output file for A2
Log4j.appender.A2.MaxFileSize = 1KB
#8 define the number of backup files for A2
Log4j.appender.A2.MaxBackupIndex = 3
The layout mode for the #9 definition A2 is patternlayout
Log4j.appender.A2.layout = Org.apache.log4j.PatternLayout
#10 defining the output format of the A2
Log4j.appender.A2.layout.ConversionPattern =%d{yyyy-mm-dd hh:mm:ss}:%p%t%c-%m%n

log4j the format meaning of the Conversionpattern parameter-go

Related Article

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.