private synchronized void setFlush ( boolean immediateFlush ) { try { Set < FileAppender > flushedFileAppenders = new HashSet < FileAppender > ( ) ; Enumeration < ? > currentLoggers = LogManager . getLoggerRepository ( ) . getCurrentLoggers ( ) ; while ( currentLoggers . hasMoreElements ( ) ) { Object nextLogger = currentLoggers . nextElement ( ) ; if ( nextLogger instanceof Logger ) { Logger currentLogger = ( Logger ) nextLogger ; Enumeration < ? > allAppenders = currentLogger . getParent ( ) . getAllAppenders ( ) ; while ( allAppenders . hasMoreElements ( ) ) { Object nextElement = allAppenders . nextElement ( ) ; if ( nextElement instanceof FileAppender ) { FileAppender fileAppender = ( FileAppender ) nextElement ; if ( ! flushedFileAppenders . contains ( fileAppender ) ) { flushedFileAppenders . add ( fileAppender ) ; fileAppender . setImmediateFlush ( immediateFlush ) ; } } } } } } catch ( Throwable e ) { LOG . error ( "Failed flushing logs" , e ) ; } }
Set immediateFlush property for all file appenders .