About the configuration and parameters of log4j

Source: Internet
Author: User

LOG4J configuration:

Pom.xml

1 <Properties>2     ...3     <slf4j.version>1.7.21</slf4j.version>4     <log4j.version>1.2.17</log4j.version>5     ...6  </Properties>7 8 <Dependencies>9 ...Ten <!--log File Management Pack - One     <!--Log Start - A     <Dependency> -       <groupId>Log4j</groupId> -       <Artifactid>Log4j</Artifactid> the       <version>${log4j.version}</version> -     </Dependency> -     <Dependency> -       <groupId>Org.slf4j</groupId> +       <Artifactid>Slf4j-api</Artifactid> -       <version>${slf4j.version}</version> +     </Dependency> A  at     <Dependency> -       <groupId>Org.slf4j</groupId> -       <Artifactid>Slf4j-log4j12</Artifactid> -       <version>${slf4j.version}</version> -     </Dependency> - ... in </Dependencies>

Log4j.properties

#定义LOG输出级别log4j. rootlogger=info,console,file# definition Log Output destination to console log4j.appender.console= The org.apache.log4j.consoleappenderlog4j.appender.console.target=system.out# provides the flexibility to specify the log output format, The following line specifies the specific format log4j.appender.Console.layout = ORG.APACHE.LOG4J.PATTERNLAYOUTLOG4J.APPENDER.CONSOLE.LAYOUT.CONVERSIONPATTERN=[%C]-%m%n# When the file size reaches the specified size, a new file is generated log4j.appender.File = org.apache.log4j.rollingfileappender# Specifies the output directory Log4j.appender.File.File =/ home/matto/ideaprojects/workspacegit/testmaven/logs/ssm.log# definition file Maximum size log4j.appender.File.MaxFileSize = 10mb# Output so log, if switched to debug indicates output debug above level log Log4j.appender.File.Threshold = ALLlog4j.appender.File.layout = Org.apache.log4j.PatternLayoutlog4j.appender.File.layout.ConversionPattern =[%p] [%d{yyyy-mm-dd hh\:mm\:ss}][%c]% m%n# another, I used to ... Log4j.rootlogger=debug, a1log4j.appender.a1.layout= Org.apache.log4j.patternlayoutlog4j.appender.a1.layout.conversionpattern=>>>%d%5p [%t] (%F:%L)-%m% Nlog4j.appender.a1.datepattern= '. ' Yyyy-mm-ddlog4j.appender.a1=org.apache.log4j.consoleappenDer 

Detailed parameters:

log4j Configuration Explanation 1:

# # #把日志信息输出到控制台 # #
Log4j.appender.stdout=org.apache.log4j.consoleappender
Log4j.appender.stdout.target=system.out
Log4j.appender.stdout.layout=org.apache.log4j.patternlayout
LOG4J.APPENDER.STDOUT.LAYOUT.CONVERSIONPATTERN=%D{YYYY-MM-DD hh:mm:ss}%m%n

# # #把日志信息输出到文件: test.log###
Log4j.appender.file=org.apache.log4j.fileappender
Log4j.appender.file.file=test.log
Log4j.appender.file.layout=org.apache.log4j.patternlayout
LOG4J.APPENDER.FILE.LAYOUT.CONVERSIONPATTERN=%D{YYYY-MM-DD hh:mm:ss}%m%n

# # #设置优先级别, and Output source # # #
Log4j.rootlogger=debug,stdout,file

Configuration explanation:
The log4j charge Xuzhi request is output to multiple output sources, and an output source is called a appender. There are two Appender, the first named stdout, using Consoleappender,
By configuring the target property, the log information is written to the console, and the effect is equivalent to printing the information directly to the System.out. The second appender is named file and uses the
Fileappender, the log information is written to the specified file (test.log) by configuring the Files property.
layout Specifies the style of the log information output. Both of the above outputs use Patternlayout, which gives you the flexibility to specify layout patterns. But to configure layout. Conversionpattern Property,
Where:%d{yyyy-mm-dd HH:mm:ss} is used to set the output log time, the output format is similar to 2009-05-13 09:00:00;%m is used to output the message specified in the code;%n is used to output a carriage return character;
%l is used to output where the log event occurs, including the class name, the thread that occurred, and the number of rows in the code. For example: If the output is Java.ch04.TestLog4j.min (Testlog4j.java:12),
Indicates that the log event occurred in the main thread in the Testlog4j class, with the number of lines in the code being line 12th.
The log information has the output priority level, the priority from high to low is FATA, error, warn, info, Debug. The last sentence above sets the priority level to debug, and the setup log is output to the console separately and
The Test.log file.

--------------------------------------------------------------------------------------------------------------- ----------------------------------

LOG4J Configuration Explanation 2:

#log4j. Rootlogger=debug,a1,r
# # # Set Priority (FATA, error, warn, debug, info), and output source (console, file) # # #
Log4j.rootlogger=info,a1,r
# # # to output log information to the console # # #
# # # A1,r Output Source Name # # #
# # # Consoleappender: Write log messages to the console # # #
Log4j.appender.a1=org.apache.log4j.consoleappender
# # # Output style layout mode # # #
Log4j.appender.a1.layout=org.apache.log4j.patternlayout
# #%c: Package name. file name. %p: Output level,%m: The message specified in the output code,%n: Outputs a carriage return newline character,%l: the location where the output log information occurs, including the class name, the thread that occurred, the number of rows, and the%t output a tab # # #
Log4j.appender.a1.layout.conversionpattern=%-d{yyyy-mm-dd hh:mm:ss,sss} [%c]-[%p]%m%n

# # # Rollingfileappender: Log information loop to write to file, Fileappender: Write log information to file # # #
Log4j.appender.r=org.apache.log4j.rollingfileappender
# # # Setting the log information file named Bbscs7log.txt # # # #
Log4j.appender.r.file=bbscs7log.txt
# # # Setting log information file size 500KB # # #
log4j.appender.r.maxfilesize=500kb
# # # Set the total number of log information files up to 10 # # #
log4j.appender.r.maxbackupindex=10
# # # Output style layout mode # # #
Log4j.appender.r.layout=org.apache.log4j.patternlayout
Log4j.appender.r.layout.conversionpattern=%d%d%d%d%d%d%d{yyyy-mm-dd hh:mm:ss,sss} [%t] [%c] [%p]-%m%n

#log4j. Logger.org.springframework.transaction.interceptor=debug

About the configuration and parameters of log4j

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.