1 17 package org.apache.log.output.io; 18 19 import java.io.File ; 20 import java.io.FileOutputStream ; 21 import java.io.IOException ; 22 import org.apache.log.LogEvent; 23 import org.apache.log.format.Formatter; 24 25 33 public class SafeFileTarget 34 extends FileTarget 35 { 36 44 public SafeFileTarget( final File file, final boolean append, final Formatter formatter ) 45 throws IOException 46 { 47 super( file, append, formatter ); 48 shutdownStream(); 49 } 50 51 56 public synchronized void processEvent( final LogEvent event ) 57 { 58 if( !isOpen() ) 59 { 60 getErrorHandler().error( "Writing event to closed stream.", null, event ); 61 return; 62 } 63 64 try 65 { 66 final FileOutputStream outputStream = 67 new FileOutputStream ( getFile().getPath(), true ); 68 setOutputStream( outputStream ); 69 } 70 catch( final Throwable throwable ) 71 { 72 getErrorHandler().error( "Unable to open file to write log event.", throwable, event ); 73 return; 74 } 75 76 super.processEvent( event ); 78 79 shutdownStream(); 80 } 81 } 82 | Popular Tags |