log4j.properties configuration details

1. Basic configuration

log4j.rootCategory=INFO,stdout,R

log4j.appender.stdout=org.apache.log4j.ConsoleAppender

log4j.appender.stdout.layout=org.apache.log4j.PatternLayout

log4j.appender.stdout.layout.ConversionPattern=[QC] %p [%t] %C.%M(%L) | %m%n

log4j.appender.R = org.apache.log4j.DailyRollingFileAppender

log4j.appender.R.File=D:\\Tomcat 5.5.25\\logs\\qc.log

log4j.appender.R.layout=org.apache.log4j.PatternLayout

log4j.appender.R.layout.ConversionPattern=%d-[TS] %p %t %c - %m%n

#Whether to append write

log4j.addivity.org.apache = true

 

log4j.logger.ServerInfo = INFO, appender1, appender2 Configuration function?

 

2. Framework configuration

log4j.logger.com.neusoft=DEBUG

log4j.logger.com.opensymphony.oscache=ERROR

log4j.logger.net.sf.navigator=ERROR

log4j.logger.org.apache.commons=ERROR

log4j.logger.org.apache.struts=WARN

log4j.logger.org.displaytag=ERROR

log4j.logger.org.springframework=DEBUG

log4j.logger.com.ibatis.db=WARN

log4j.logger.org.apache.velocity=FATAL

log4j.logger.com.canoo.webtest=WARN

log4j.logger.org.hibernate.ps.PreparedStatementCache=WARN

log4j.logger.org.hibernate=DEBUG

log4j.logger.org.logicalcobwebs=WARN

3. Configuration instructions

1) log4j.rootCategory=INFO,stdout,R

This sentence is to output the log information with the level of INFO to the two destinations of stdout and R. The definitions of stdout and R are in the following code, which can be named arbitrarily.

The levels can be divided into OFF, FATAL, ERROR, WARN, INFO, DEBUG, ALL. If the configuration is OFF, no information will be displayed. If the configuration is INFO, only the log information of INFO, WARN, and ERROR will be displayed, and the DEBUG information will not be displayed. For specific explanation, please refer to the logger in the third part of the definition configuration file.

2) log4j.appender.stdout=org.apache.log4j.ConsoleAppender

This sentence defines what type of output named stdout is, which can be:

a) org.apache.log4j.ConsoleAppender (console)

b) org.apache.log4j.FileAppender (file)

c) org.apache.log4j.DailyRollingFileAppender (generates a log file every day)

d) org.apache.log4j.RollingFileAppender (a new file is generated when the file size reaches the specified size)

e) org.apache.log4j.WriterAppender (send log information to any specified place in stream format)

For specific explanations, please refer to the Appender in the definition configuration file in Part 4.

3) log4j.appender.stdout.layout=org.apache.log4j.PatternLayout

This sentence defines the type of layout of the output named stdout, which can be:

a) org.apache.log4j.HTMLLayout (layout in HTML form)

b) org.apache.log4j.PatternLayout (the layout pattern can be flexibly specified)

c) org.apache.log4j.SimpleLayout (contains log information level and information string)

d) org.apache.log4j.TTCCLayout (including log generation time, thread, category, etc.)

For specific explanations, please refer to the Layout in the third part of the definition configuration file.

4) log4j.appender.stdout.layout.ConversionPattern= [QC] %p [%t] %C.%M(%L) | %m%n

If you use the pattern layout, you need to specify the specific format ConversionPattern for printing information. The printing parameters are as follows:

a) %m outputs the message specified in the code

b) %p output priority, ie DEBUG, INFO, WARN, ERROR, FATAL

c) %r is the number of milliseconds it takes to output the log information since the application was started

d) %c The category to which the output belongs, usually the full name of the category

e) %t output the thread name that generated the log event

f) %n outputs a carriage return and line feed, "rn" for Windows platforms and "n" for Unix platforms

g) %d output the date or time of the log time point, the default format is ISO8601, you can also specify the format after it, for example: %d{yyyy MMM dd HH:mm:ss,SSS}, the output is similar to: October 2002 18th 22:10:28, 921

h) %l outputs the location of the log event, including the category name, the thread where it occurred, and the number of lines in the code.

i) [QC] is the beginning of the log information, which can be any character, usually the project abbreviation.

An example of the output information is as follows:

[QC] DEBUG [main] AbstractBeanFactory.getBean(189) | Returning cached instance of singleton bean 'MyAutoProxy'

For specific explanations, please refer to the formatted log information in the third part of the definition configuration file.

5) log4j.appender.R = org.apache.log4j.DailyRollingFileAppender

This sentence is the same as line 3. Define the type of output named R to produce a log file per day.

6) log4j.appender.R.File=D:\\Tomcat 5.5\\logs\\qc.log

This sentence defines the file name of the output named R: D:\\Tomcat 5.5\\logs\\qc.log

You can modify it yourself.

7) log4j.appender.R.layout=org.apache.log4j.PatternLayout

Same as line 4.

8) log4j.appender.R.layout.ConversionPattern=%d-[TS] %p %t %c - %m%n

Same as line 5.

9) log4j.logger.com.way=DEBUG

Specifies that all classes under the com.way package are rated DEBUG. You can change com.way to the package name used in your own project.

10) log4j.logger.com.opensymphony.oscache=ERROR

11) log4j.logger.net.sf.navigator=ERROR

These two sentences are to set the error level of these two packages to ERROR. If EHCache is not configured in the project, these two sentences are not needed.

12) log4j.logger.org.apache.commons=ERROR

13) log4j.logger.org.apache.struts=WARN

These two sentences are packages of struts.

14) log4j.logger.org.displaytag=ERROR

This sentence is the package of displaytag. (Used on the QC Questions List page)

15) log4j.logger.org.springframework=DEBUG

This sentence is a Spring package.

16) log4j.logger.org.hibernate.ps.PreparedStatementCache=WARN

17) log4j.logger.org.hibernate=DEBUG

These two sentences are the hibernate package.

The settings of these packages can be customized according to the actual situation of the project.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326404406&siteId=291194637