For the Appender interface, LOG4J provides the following implementations:
- Org.apache.log4j.ConsoleAppender (console)
- Org.apache.log4j.FileAppender (file)
- Org.apache.log4j.DailyRollingFileAppender (a log file is generated every day)
- Org.apache.log4j.RollingFileAppender (A new log file is generated when the file size reaches the specified size, and a numeric sequence number is automatically added to the file name.) )
- Org.apache.log4j.WriterAppender (send log information in stream format to any specified location)
By default, the child logger inherits all appenders from the parent logger.
Let's take a look at the relationships of these implementation classes:
The first two are relatively good understanding, the following emphasis on the latter 3 kinds of
First, Rollingfileappende.
This is a special fileappender, when the log file in the end of the specified size, then the original journal file will be added to the sequence number, such as xxx.1
It is important to note that if more than the specified size (maxfilesize) need to add a log file, then the original xxx.1 file will be added 1 into xxx.2
That is, the larger the number the log file records the earlier the log time!
In addition, you can set the maximum number (Maxbackupindex), if the number is exceeded, then the oldest record will be overwritten.
A common configuration file is given below
[Plain]View Plain Copy
- LOG4J.APPENDER.D = Org.apache.log4j.DailyRollingFileAppender
- Log4j.appender.d.file = D:/log/log.log
- Log4j.appender.d.append = True
- Log4j.appender.d.threshold = DEBUG
- log4j.appender.d.maxfilesize=10mb
- log4j.appender.d.maxbackupindex=10
- Log4j.appender.d.layout = Org.apache.log4j.PatternLayout
- Log4j.appender.d.layout.conversionpattern =%-d{yyyy-mm-dd HH:mm:ss} [%t:%r]-[%p]%m%n
Dailyrollingfileappenderr
This is really nothing special, after the day after the log file will be xxx+ yesterday's date to name, that is, a daily log file
Writerappende
This is actually the parent class of Consoleappender and Fileappender, which is generally not used directly, but instead uses its subclasses, such as Consoleappender
Reprint Address: http://blog.csdn.NET/u012345283/article/details/39264245
log4j output Terminal (Appender) detailed