Log4j 1.2 configuration Summary

Source: Internet
Author: User

First paste a configuration file for properties, and then explain the meaning of the parameter.

# Global logging configurationlog4j.rootLogger=ERROR,stdout# Console output...log4j.appender.stdout=org.apache.log4j.ConsoleAppenderlog4j.appender.stdout.layout=org.apache.log4j.PatternLayoutlog4j.appender.stdout.layout.ConversionPattern=%d %p [%c] - %m%n# Rolling log file output...log4j.appender.fileout=org.apache.log4j.DailyRollingFileAppenderlog4j.appender.fileout.File=${catalina.base}/logs/common/common.log
log4j.appender.fileout.DatePattern=‘.‘yyyy-MM-ddlog4j.appender.fileout.layout=org.apache.log4j.PatternLayoutlog4j.appender.fileout.layout.ConversionPattern=%d %p [%c] - %m%n#servicelog4j.logger.com.service= DEBUG, servicelog4j.appender.service = org.apache.log4j.RollingFileAppenderlog4j.appender.service.MaxFileSize=5mblog4j.appender.service.Append=true
log4j.appender.fileout.MaxBackupIndex=10log4j.appender.service.File=${catalina.base}/logs/service.loglog4j.appender.service.layout=org.apache.log4j.PatternLayoutlog4j.appender.service.layout.ConversionPattern=%d{yyyy-MM-dd HH\:mm\:ss,SSS} [%p] - %m%n#systemlog4j.logger.com.system= DEBUG, systemlog4j.appender.system= org.apache.log4j.RollingFileAppenderlog4j.appender.system.MaxFileSize=5mblog4j.appender.system.Append=true log4j.appender.system.File=${catalina.base}/logs/system.loglog4j.appender.system.layout=org.apache.log4j.PatternLayoutlog4j.appender.system.layout.ConversionPattern=%d{yyyy-MM-dd HH\:mm\:ss,SSS} [%p] - %m%n

 

1. There are generally 6 levels of log output: trace, debug, info, warn, error, and fatal. The level increases sequentially, but generally four levels are commonly used.

2. First, define the logger name. The related configurations are named differently.

# Configure the root Logger
Log4j. rootlogger = [level], appendername1, appendername2 ,...

Alternatively, use the inheritance configuration with the package name

log4j.logger.com.service= [ level ], service
log4j.logger.com.system= [ level ], system

Because logger in log4j has the inheritance feature of Java, in this instance'Com. Service'All classes under the package can use the appender service to output information above the [level] level.

3.AppenderFor the log output destination, log4j provides the following types of appender:

 

Org. apache. log4j. consoleappender # console Org. apache. log4j. fileappender # file Org. apache. log4j. dailyrollingfileappender # generates a log file org every day. apache. log4j. rollingfileappender # a new file org is generated when the file size reaches the specified size. apache. log4j. writerappender # Send log information to any specified place in the stream format

 

4.Layout: Log output format. layout provided by log4j includes the following types:

Org. apache. log4j. htmllayout # layout Org. apache. log4j. patternlayout # You can flexibly specify the layout mode Org. apache. log4j. simplelayout # The log information level and information string Org. apache. log4j. ttcclayout # contains the log generation time, thread, category, and other information

5.Layout. conversionpattern:

% M # message % P specified in the output Code # output priority, that is, debug, info, warn, error, fatal % R # Number of milliseconds consumed by outputting log information from application startup to output % C # category of output, this is usually the full name of the Class % T # Name of the thread that outputs the log event % N # output a carriage return linefeed % d # date or time of the log output time point, the default format is iso8601. You can also specify a format later, for example, % d {YYY Mmm dd hh: mm: SS, SSS} % L # location where the log event is output, this includes the category name, the thread that occurs, and the number of lines in the code.

6. append = true: True indicates that the message is added to the specified file. If false, the message overwrites the content of the specified file. The default value is true.

7. file output log file path and name

8. Use datepattern dailyrollingfileappender

 

Datepattern = ''.'' yyyy-ww: The file is rolled every week, that is, a new file is generated every week. You can also specify monthly, weekly, daily, and hour/minute. The corresponding format is as follows: 1 )''. ''yyyy-MM: 2) per month )''. ''yyyy-ww: 3) per week )''. ''yyyy-mm-DD: 4 every day )''. ''yyyy-mm-dd-A: twice a day (5 )''. ''yyyy-mm-dd-hh: 6 )''. ''yyyy-mm-dd-hh-MM: minute

 

9. maxfilesize rollingfileappender. Once the log reaches a certain size, a new file is generated.

Maxbackupindex rollingfileappender indicates that only the corresponding number of backup files are saved.

 

Log4j 1.2 configuration Summary

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.