The log4j. properties configuration file is described as follows:
# Set root logger level to debug and its only appender to A1
# Log4j has five levels of logger
# Fatal 0
# Error 3
# Warn 4
# INFO 6
# Debug 7
Configure the root Logger with the Syntax:
# Log4j. rootlogger = [level], appendername, appendername ,...
Log4j. rootlogger = info, A1, R
# This sentence indicates that all logs are output.
# If it is log4j. rootlogger = warn, it means only warn, error, fatal
# Output. debug and info will be blocked.
# A1 is set to be a consoleappender.
# The appender in log4j has several layers, such as the console, files, Gui components, and even an interface server, NT event recorder, and Unix Syslog daemon.
# Leleappender output to the console
Log4j. appender. A1 = org. Apache. log4j. leleappender
# Output layout used by a1. log4j provides four layout S: org. Apache. log4j. htmllayout (layout in HTML form)
# Org. Apache. log4j. patternlayout (you can flexibly specify the layout mode ),
# Org. apache. log4j. SimpleLayout (including the log information level and information string ),
# Org. apache. log4j. TTCCLayout (including the log generation time, thread, category, and other information)
Log4j. appender. A1.layout = org. apache. log4j. PatternLayout
# Flexibly define the output format. For details, see log4j javadoc org. apache. log4j. PatternLayout.
# D time ....
Log4j. appender. a1.layout. conversionpattern = %-d {yyyy-mm-dd hh: mm: SS} [% C]-[% P] % m % N
# R extension output to file rollingfileappender, which can provide a log backup function.
Log4j. appender. r = org. Apache. log4j. rollingfileappender
# Log File Name
Log4j. appender. R. File = log4j. Log
# Log File Size
Log4j. appender. R. maxfilesize = 100kb
# Saving a backup file
Log4j. appender. R. maxbackupindex = 1 log4j. appender. R. layout = org. Apache. log4j. ttcclayout
# Log4j. appender. R. layout. conversionpattern = %-d {yyyy-mm-dd hh: mm: SS} [% C]-[% P] % m % N
Configure the root Logger with the Syntax:
Log4j. rootLogger = [level], appenderName, appenderName ,...
Level is the log record priority.
Appendername specifies where the log information is output. You can specify multiple output destinations at the same time.
Configure the Appender of the log output destination. Its syntax is
Log4j. appender. appenderName = fully. qualified. name. of. appender. class
Log4j. appender. appenderName. option1 = value1
...
Log4j. appender. appenderName. option = valueN
Log4j provides the following types of appender:
Org. Apache. log4j. leleappender (console ),
Org. Apache. log4j. fileappender (file ),
Org. Apache. log4j. dailyrollingfileappender (a log file is generated every day ),
Org. Apache. log4j. rollingfileappender (a new file is generated when the file size reaches the specified size ),
Org. apache. log4j. WriterAppender (send log information to any specified place in stream format)
Configure the log information format (layout). Its syntax is:
Log4j. appender. appenderName. layout = fully. qualified. name. of. layout. class
Log4j. appender. appenderName. layout. option1 = value1
....
Log4j. appender. appenderName. layout. option = valueN
Log4j provides the following layout types:
Org. apache. log4j. HTMLLayout (in the form of HTML tables ),
Org. apache. log4j. PatternLayout (you can flexibly specify the layout mode ),
Org. apache. log4j. SimpleLayout (including the log information level and information string ),
Org. apache. log4j. TTCCLayout (including the log generation time, thread, category, and so on)