How to rotate a log4j log manually

前端 未结 3 1830
忘了有多久
忘了有多久 2021-01-20 15:04

I have log4j configured to rotate the log every day.

In special situations I would like to trigger an additional log rotation manually.

Is this possible - an

3条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-01-20 15:52

    If you're keeping track of your appenders, you could call

    https://logging.apache.org/log4j/1.2/apidocs/org/apache/log4j/RollingFileAppender.html#rollOver()

    That should do it. I guess it's also possible to iterate through all appenders you can find starting from root level - just make sure you keep track of which appenders you already rolled.

提交回复
热议问题