/** * 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() ); }
/** * Get a new log instance for the specified file if it is not open yet! * @param filename The log file to open * @param exact is this an exact filename (false: prefix of name in temp directory) * @return the LogWriter object */ // synchronizing logWriter singleton instance PDI-6840 public static final synchronized LogWriter getInstance( String filename, boolean exact ) throws KettleException { if ( logWriter != null ) { // OK, see if we have a file appender already for this // if ( logWriter.pentahoLogger.getAppender( LogWriter.createFileAppenderName( filename, exact ) ) == null ) { logWriter.fileAppender = createFileAppender( filename, exact ); logWriter.addAppender( logWriter.fileAppender ); } return logWriter; } logWriter = new LogWriter( filename, exact ); return logWriter; }
/** * 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 ); } }
/** * 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 ); } }