How do you flush a buffered log4j FileAppender?

前端 未结 7 1756
感动是毒
感动是毒 2020-12-01 09:49

In log4j, when using a FileAppender with BufferedIO=true and BufferSize=xxx properties (i.e. buffering is enabled), I want to be able to flush the log during normal shutdown

7条回答
  •  甜味超标
    2020-12-01 10:03

    Maybe you could override WriterAppender#shouldFlush( LoggingEvent ), so it would return true for a special logging category, like log4j.flush.now, and then you call:

    LoggerFactory.getLogger("log4j.flush.now").info("Flush")
    

    http://logging.apache.org/log4j/1.2/apidocs/org/apache/log4j/WriterAppender.html#shouldFlush%28org.apache.log4j.spi.LoggingEvent%29

提交回复
热议问题