quote
For example:
log4j.rootLogger=INFO, Console
.......
#log4j for QUEUE
log4j.logger.Q=INFO,queue
log4j.additivity.Q=false
log4j.appender.queue=org.apache.log4j.RollingFileAppender
log4j.appender.queue.File=logs/mcc-app-queue.log
log4j.appender.queue.DatePattern='-'yyyy-MM-dd-HH-mm'.txt'
log4j.appender.queue.MaxFileSize=20480KB
log4j.appender.queue.MaxBackupIndex=200
log4j.appender.queue.layout=org.apache.log4j.PatternLayout
log4j.appender.queue.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %p %C.%M(%L) : %m%n
Explanation:
Q is the log name, queue is append
log4j.additivity.Q=false This line means not inheriting root, that is, not printing on the console, according to its own The defined append(queue) prints
RollingFileAppender is a continuous file printing method.
MaxFileSize specifies 20M to generate a new log file
. The maximum log file index generated by MaxBackupIndex is 200, that is, a maximum of 200 log files will be saved.
%d{yyyy-MM-dd HH:mm:ss} %p %C.%M(%L) : %m%n log printing format, the details are as follows:
%d{yyyy-MM-dd HH:mm:ss} is the printing time format
%p is the printing log level, such as: info ,warn,error
%C is to print the full class name (including the package path), such as: com.test.Test
%M is the method name, such as: sayHello
%C.%M If configured, the print is com.test.Test. sayHello
%L is the number of lines where the log is printed, (%L), that is (104), indicating that the 104 lines
%m is the content to be printed, such as: log.info("xxxx"), then %m is xxx
%n is to output a blank line.
If it is log.info("xxx"). Then according to the format of %d{yyyy-MM-dd HH:mm:ss} %p %C.%M(%L) : %m%n, the printed content is
2014-07-23 19:44:42 INFO com.test.Test.sayHello(135) : xxx