gpt4 book ai didi

java - Log4j 删除超过一个月的日志

转载 作者:太空宇宙 更新时间:2023-11-04 14:02:55 25 4
gpt4 key购买 nike

我有以下 Log4J 配置,如何删除超过 1 个月的日志?

Define the root logger with appender file

log =log/

log4j.rootLogger = ERROR, FILE

Define the file appender

log4j.appender.FILE=org.apache.log4j.DailyRollingFileAppender

Set the name of the file

log4j.appender.FILE.File=${log}/server.log

Set the immediate flush to true (default)

log4j.appender.FILE.ImmediateFlush=true

Set the threshold to debug mode

log4j.appender.FILE.Threshold=debug

Set the append to false, should not overwrite

log4j.appender.FILE.Append=true

Set the DatePattern

log4j.appender.FILE.DatePattern='.' yyyy-MM-dd-a

Define the layout for file appender

log4j.appender.FILE.layout=org.apache.log4j.PatternLayout

log4j.appender.FILE.layout.conversionPattern=%m%n

最佳答案

您需要使用 RollingFileAppender 并设置 MaxBackupIndex 计数。

关于java - Log4j 删除超过一个月的日志,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29143688/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com