Switch to] log4cxx backup by time and size

Source: Internet
Author: User

 1. log files are generated at a certain time. The configuration file is as follows: 

# Set root logger level to Error and Its only appender to A1.

Log4j. rootlogger = error, R

 

# R is set to be a dailyrollingfileappender.

Log4j. appender. r = org. Apache. log4j. dailyrollingfileappender

Log4j. appender. R. File = backup. Log

Log4j. appender. R. datepattern = '. 'yyyy-mm-dd

Log4j. appender. R. layout = org. Apache. log4j. patternlayout

Log4j. appender. R. layout. conversionpattern = %-d {yyyy-mm-dd hh: mm: SS} [% C]-[% P] % m % N

 

The preceding configuration generates a backup file every day. The name of the backup file is backup. log.

The specific effect is as follows: the log information of the current day is recorded in the backup. log file, and the log of the previous day is recorded in the file named backup. log. yyyy-mm-dd.

Similarly, if you need to generate a file every month, you can modify the above Configuration:

Set Log4j. appender. R. datepattern = '. 'yyyy-mm-dd

Change Log4j. appender. R. datepattern = '. 'yyyy-mm

 

Cut logs by minute: log4j. appender. a1.datepattern = '. 'yyyy-mm-dd-hh-mm

 

Ii. Automatic Generation of new log files based on the log file size

The configuration file is as follows:

# Set root logger level to Error and Its only appender to A1.

Log4j. rootlogger = error, R

 

# R is set to be a rollingfileappender.

Log4j. appender. r = org. Apache. log4j. rollingfileappender

 

Log4j. appender. R. File = backup. Log

# Log4j. appender. R. maxfilesize = 100kb

 

# Keep one backup file

Log4j. appender. R. maxbackupindex = 1

Log4j. appender. R. layout = org. Apache. log4j. patternlayout

Log4j. appender. R. layout. conversionpattern = %-d {yyyy-mm-dd hh: mm: SS} [% C]-[% P] % m % N

 

Where:

# Log File Size

Log4j. appender. R. maxfilesize = 100kb

# Saving a backup file

Log4j. appender. R. maxbackupindex = 1

 1. log files are generated at a certain time. The configuration file is as follows: 

# Set root logger level to Error and Its only appender to A1.

Log4j. rootlogger = error, R

 

# R is set to be a dailyrollingfileappender.

Log4j. appender. r = org. Apache. log4j. dailyrollingfileappender

Log4j. appender. R. File = backup. Log

Log4j. appender. R. datepattern = '. 'yyyy-mm-dd

Log4j. appender. R. layout = org. Apache. log4j. patternlayout

Log4j. appender. R. layout. conversionpattern = %-d {yyyy-mm-dd hh: mm: SS} [% C]-[% P] % m % N

 

The preceding configuration generates a backup file every day. The name of the backup file is backup. log.

The specific effect is as follows: the log information of the current day is recorded in the backup. log file, and the log of the previous day is recorded in the file named backup. log. yyyy-mm-dd.

Similarly, if you need to generate a file every month, you can modify the above Configuration:

Set Log4j. appender. R. datepattern = '. 'yyyy-mm-dd

Change Log4j. appender. R. datepattern = '. 'yyyy-mm

 

Cut logs by minute: log4j. appender. a1.datepattern = '. 'yyyy-mm-dd-hh-mm

 

Ii. Automatic Generation of new log files based on the log file size

The configuration file is as follows:

# Set root logger level to Error and Its only appender to A1.

Log4j. rootlogger = error, R

 

# R is set to be a rollingfileappender.

Log4j. appender. r = org. Apache. log4j. rollingfileappender

 

Log4j. appender. R. File = backup. Log

# Log4j. appender. R. maxfilesize = 100kb

 

# Keep one backup file

Log4j. appender. R. maxbackupindex = 1

Log4j. appender. R. layout = org. Apache. log4j. patternlayout

Log4j. appender. R. layout. conversionpattern = %-d {yyyy-mm-dd hh: mm: SS} [% C]-[% P] % m % N

 

Where:

# Log File Size

Log4j. appender. R. maxfilesize = 100kb

# Saving a backup file

log4j. appender. R. maxbackupindex = 1

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.