How to control log file with daily rolling and max file size by log4j?

后端 未结 3 1415
情书的邮戳
情书的邮戳 2021-02-04 08:40

I would like to create log file that can be rolled at the beginning of the next day or if it\'s reached to specified file size and log file must be contained inside date folder.

3条回答
  •  不思量自难忘°
    2021-02-04 09:34

    From the RollingFileAppender documentation

    To be of any use, a RollingFileAppender instance must have both a RollingPolicy and a TriggeringPolicy set up.... TimeBasedRollingPolicy acts both as a RollingPolicy and a TriggeringPolicy.

    Hence, your SizeBasedTriggeringPolicy gets ignored since TimeBasedRollingPolicy is configured above. The only way to accommodate your requirement will be a custom classes implementation.

    Also, If size of a log file really matters, you may consider using automatic gzip compression to eliminate SizeBasedTriggeringPolicy and only have your logs roll every day.

提交回复
热议问题