public void writeToDisk ( ) { if ( ! initialized ) { initializeLog ( ) ; } Writer writer = null ; try { FileOutputStream fileOut = new FileOutputStream ( this . fileName + ( this . nbOfFile == 0 ? ".log" : this . nbOfFile + ".log" ) , true ) ; writer = new OutputStreamWriter ( fileOut , IoUtils . UTF8_CHARSET ) ; final XStream xstream = createTrustingXStream ( ) ; WorkingMemoryLog log = null ; synchronized ( this . events ) { log = new WorkingMemoryLog ( new ArrayList < LogEvent > ( this . events ) ) ; clear ( ) ; } writer . write ( xstream . toXML ( log ) + "\n" ) ; } catch ( final FileNotFoundException exc ) { throw new RuntimeException ( "Could not create the log file. Please make sure that directory that the log file should be placed in does exist." ) ; } catch ( final Throwable t ) { logger . error ( "error" , t ) ; } finally { if ( writer != null ) { try { writer . close ( ) ; } catch ( Exception e ) { } } } if ( terminate ) { closeLog ( ) ; terminate = true ; } else if ( split ) { closeLog ( ) ; this . nbOfFile ++ ; initialized = false ; } }
All events in the log are written to file . The log is automatically cleared afterwards .