Need a working example of configuring log4j RollingFileAppender via properties

前端 未结 4 1040
北恋
北恋 2021-02-02 18:10

I am using log4j for logging, and a property file for configuration. Currently, my log files are too big (3.5 GB is too large for a log file). So think I need to use Ro

4条回答
  •  春和景丽
    2021-02-02 18:40

    When we need log files to be rolled on a daily basis, we should be using DailyRollingFileAppender instead of RollingFileAppender. You do not need to specify the MaxFileSize limit instead only DatePattern is enough for rolling files based on frequency. I have tried the below configuration in log4j.properties file for rolling log files every minute.

    log4j.appender.infoAppender=org.apache.log4j.DailyRollingFileAppender

    log4j.appender.infoAppender.Threshold=INFO

    log4j.appender.infoAppender.DatePattern='.' yyyy-MM-dd HH-mm

    log4j.appender.infoAppender.File=C:/logs/info.log

提交回复
热议问题