[chor](log) Change log4j rollover strategy to 'max' (#32116)

The log file names are in the format fe.log.${date}-${index}, e.g.
```
fe.log.20240311-1
fe.log.20240311-2
fe.log.20240311-3
...
```
In the previous, fe.log/fe.audit.log will be renamed to fe.log.xxx-1/fe.audit.log.xxx-1
with the minimum index `1` when they reach rotation size. e.g.
```
fe.log.20240311-1 -> fe.log.20240311-2
fe.log.20240311-2 -> fe.log.20240311-3
fe.log.20240311-3 -> fe.log.20240311-4
fe.log            -> fe.log.20240311-1
```

there are some drawbacks
1. log4j needs to rename all existing rotated log to spare the
   index `1`
2. it's hard to deal with the duplicated names, because every time the
   log rotates, it starts from index `1`

After this change, the log will rename to a file name with larger index
instead of `1`. e.g. when rotate
```
fe.log.20240311-1
fe.log.20240311-2
fe.log.20240311-3
fe.log -> fe.log.20240311-4
```
This commit is contained in:
Gavin Chou
2024-03-20 14:11:58 +08:00
committed by yiguolei
parent 6d401451cc
commit 1b0c4d3aa2

View File

@ -56,7 +56,7 @@ public class Log4jConfig extends XmlConfiguration {
+ " <TimeBasedTriggeringPolicy/>\n"
+ " <SizeBasedTriggeringPolicy size=\"${sys_roll_maxsize}MB\"/>\n"
+ " </Policies>\n"
+ " <DefaultRolloverStrategy max=\"${sys_roll_num}\" fileIndex=\"min\">\n"
+ " <DefaultRolloverStrategy max=\"${sys_roll_num}\" fileIndex=\"max\">\n"
+ " <Delete basePath=\"${sys_log_dir}/\" maxDepth=\"1\">\n"
+ " <IfFileName glob=\"fe.log.*\" />\n"
+ " <IfLastModified age=\"${sys_log_delete_age}\" />\n"
@ -71,7 +71,7 @@ public class Log4jConfig extends XmlConfiguration {
+ " <TimeBasedTriggeringPolicy/>\n"
+ " <SizeBasedTriggeringPolicy size=\"${sys_roll_maxsize}MB\"/>\n"
+ " </Policies>\n"
+ " <DefaultRolloverStrategy max=\"${sys_roll_num}\" fileIndex=\"min\">\n"
+ " <DefaultRolloverStrategy max=\"${sys_roll_num}\" fileIndex=\"max\">\n"
+ " <Delete basePath=\"${sys_log_dir}/\" maxDepth=\"1\">\n"
+ " <IfFileName glob=\"fe.warn.log.*\" />\n"
+ " <IfLastModified age=\"${sys_log_delete_age}\" />\n"
@ -86,7 +86,7 @@ public class Log4jConfig extends XmlConfiguration {
+ " <TimeBasedTriggeringPolicy/>\n"
+ " <SizeBasedTriggeringPolicy size=\"${audit_roll_maxsize}MB\"/>\n"
+ " </Policies>\n"
+ " <DefaultRolloverStrategy max=\"${audit_roll_num}\" fileIndex=\"min\">\n"
+ " <DefaultRolloverStrategy max=\"${audit_roll_num}\" fileIndex=\"max\">\n"
+ " <Delete basePath=\"${audit_log_dir}/\" maxDepth=\"1\">\n"
+ " <IfFileName glob=\"fe.audit.log.*\" />\n"
+ " <IfLastModified age=\"${audit_log_delete_age}\" />\n"