log4j output Terminal (Appender) detailed

Source: Internet
Author: User

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
    1. LOG4J.APPENDER.D = Org.apache.log4j.DailyRollingFileAppender
    2. Log4j.appender.d.file = D:/log/log.log
    3. Log4j.appender.d.append = True
    4. Log4j.appender.d.threshold = DEBUG
    5. log4j.appender.d.maxfilesize=10mb
    6. log4j.appender.d.maxbackupindex=10
    7. Log4j.appender.d.layout = Org.apache.log4j.PatternLayout
    8. 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

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.