/** * Closes the file appender opened by the getInstance(filename, exact, level) method */ public static final void closeAndRemoveFileAppender() { if ( logWriter.fileAppender != null ) { logWriter.fileAppender.close(); logWriter.pentahoLogger.removeAppender( logWriter.fileAppender ); } }
/** * This is not thread safe: please try to get the file appender yourself using the static constructor and work from there */ public FileObject getFileAppenderFile() throws IOException { return fileAppender.getFile(); }
/** * Create a file appender * @param filename The (VFS) filename (URL) to write to. * @param exact is this an exact filename of a filename to be stored in "java.io.tmp" * @return A new file appender * @throws KettleFileException In case there is a problem opening the file. */ public static final Log4jFileAppender createFileAppender( String filename, boolean exact ) throws KettleFileException { try { FileObject file; if ( !exact ) { file = KettleVFS.createTempFile( filename, ".log", System.getProperty( "java.io.tmpdir" ) ); } else { file = KettleVFS.getFileObject( filename ); } Log4jFileAppender appender = new Log4jFileAppender( file ); appender.setLayout( new Log4jKettleLayout( true ) ); appender.setName( LogWriter.createFileAppenderName( filename, exact ) ); return appender; } catch ( IOException e ) { throw new KettleFileException( "Unable to add Kettle file appender to Log4J", e ); } }
/** * This is not thread safe: please try to get the file appender yourself using the static constructor and work from there */ public InputStream getFileInputStream() throws IOException { return KettleVFS.getInputStream( fileAppender.getFile() ); }
@Override public void close() throws IOException { // remove the file appender from kettle logging if ( appender != null ) { logWriter.removeAppender( appender ); appender.close(); } Logger pigLogger = Logger.getLogger( "org.apache.pig" ); if ( pigLogger != null && pigToKettleAppender != null ) { pigLogger.removeAppender( pigToKettleAppender ); pigToKettleAppender.close(); } }
/** * Create a file appender * @param filename The (VFS) filename (URL) to write to. * @param exact is this an exact filename of a filename to be stored in "java.io.tmp" * @param append * @return A new file appender * @throws KettleFileException In case there is a problem opening the file. */ public static final Log4jFileAppender createFileAppender( String filename, boolean exact, boolean append ) throws KettleFileException { try { FileObject file; if ( !exact ) { file = KettleVFS.createTempFile( filename, ".log", System.getProperty( "java.io.tmpdir" ) ); } else { file = KettleVFS.getFileObject( filename ); } Log4jFileAppender appender = new Log4jFileAppender( file, append ); appender.setLayout( new Log4jKettleLayout( true ) ); appender.setName( LogWriter.createFileAppenderName( filename, exact ) ); return appender; } catch ( IOException e ) { throw new KettleFileException( "Unable to add Kettle file appender to Log4J", e ); } }
/** * Get the file input stream for a certain appender. * The appender is looked up using the filename * @param filename The exact filename (with path: c:\temp\logfile.txt) or just a filename (spoon.log) * @param exact true if this is the exact filename or just the last part of the complete path. * @return The file input stream of the appender * @throws IOException in case the appender ocan't be found */ public FileInputStream getFileInputStream( String filename, boolean exact ) throws IOException { Appender appender = pentahoLogger.getAppender( createFileAppenderName( filename, exact ) ); if ( appender == null ) { throw new IOException( "Unable to find appender for file: " + filename + " (exact=" + exact + ")" ); } return new FileInputStream( ( (Log4jFileAppender) appender ).getFile().getName().getPathDecoded() ); }
public FileObject getFile() { return appender == null ? null : appender.getFile(); }