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