How do you flush a buffered log4j FileAppender?

Amos picture Amos · Jun 17, 2010 · Viewed 33.5k times · Source

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 procedure. Any ideas on how to do this?

Answer

Amos picture Amos · Jun 20, 2010

Managed to answer my own question :-)

When shutting down the LogManager:

LogManager.shutdown();

all buffered logs get flushed.