public void dumpLogBuffer ( String identifier ) { final ArrayList < LogRecord > logBufferCopy ; final PrintWriter logDumper ; final OutputStream outStream ; Formatter formatter = this . getFormatter ( ) ; // Check if compression of dump file is enabled boolean disableCompression = System . getProperty ( DISABLE_DUMP_COMPR_PROP ) != null ; // If no identifying factor (eg, an incident id) was provided, get one if ( identifier == null ) { identifier = EventUtil . getDumpFileId ( ) ; } // Do some sanity checking to make sure we're not flooding the user's // disk with dump files cleanupSfDumps ( true ) ; String logDumpPath = logDumpPathPrefix + "/" + LOG_DUMP_FILE_NAME + identifier + LOG_DUMP_FILE_EXT ; if ( ! disableCompression ) { logDumpPath += LOG_DUMP_COMP_EXT ; } logger . debug ( "EventHandler dumping log buffer to {}" , logDumpPath ) ; // Copy logBuffer because this is potentially long running. synchronized ( this ) { logBufferCopy = new ArrayList <> ( logBuffer ) ; logBuffer . clear ( ) ; } File outputFile = new File ( logDumpPath ) ; /** * Because log files could potentially be very large, we should never open * them in append mode. It's rare that this should happen anyways... */ try { // If the dump path doesn't already exist, create it. if ( outputFile . getParentFile ( ) != null ) { outputFile . getParentFile ( ) . mkdirs ( ) ; } outStream = disableCompression ? new FileOutputStream ( logDumpPath , false ) : new GZIPOutputStream ( new FileOutputStream ( logDumpPath , false ) ) ; logDumper = new PrintWriter ( outStream , true ) ; } catch ( IOException exc ) { // Not much to do here, can't dump logs so exit out. logger . debug ( "Log dump failed, exception: {}" , exc . getMessage ( ) ) ; return ; } // Iterate over log entries, format them, then dump them. for ( LogRecord entry : logBufferCopy ) { logDumper . write ( formatter != null ? formatter . format ( entry ) : entry . getMessage ( ) ) ; } // Clean up logDumper . flush ( ) ; logDumper . close ( ) ; }
Dumps the contents of the in - memory log buffer to disk and clears the buffer .