public StringBuffer getBuffer( String parentLogChannelId, boolean includeGeneral ) { return getBuffer( parentLogChannelId, includeGeneral, 0 ); }
@Override public void init() { pentahoLogger = createLogger( STRING_PENTAHO_DI_LOGGER_NAME ); pentahoLogger.setAdditivity( false ); KettleLogStore.getAppender().addLoggingEventListener( this ); }
@VisibleForTesting protected String getLogBuffer( VariableSpace space, String logChannelId, LogStatus status, String limit ) { LoggingBuffer loggingBuffer = KettleLogStore.getAppender(); // if job is starting, then remove all previous events from buffer with that job logChannelId. // Prevents recursive job calls logging issue. if ( status.getStatus().equalsIgnoreCase( String.valueOf( LogStatus.START ) ) ) { loggingBuffer.removeChannelFromBuffer( logChannelId ); } StringBuffer buffer = loggingBuffer.getBuffer( logChannelId, true ); if ( Utils.isEmpty( limit ) ) { String defaultLimit = space.getVariable( Const.KETTLE_LOG_SIZE_LIMIT, null ); if ( !Utils.isEmpty( defaultLimit ) ) { limit = defaultLimit; } } // See if we need to limit the amount of rows // int nrLines = Utils.isEmpty( limit ) ? -1 : Const.toInt( space.environmentSubstitute( limit ), -1 ); if ( nrLines > 0 ) { int start = buffer.length() - 1; for ( int i = 0; i < nrLines && start > 0; i++ ) { start = buffer.lastIndexOf( Const.CR, start - 1 ); } if ( start > 0 ) { buffer.delete( 0, start + Const.CR.length() ); } } return buffer.append( Const.CR + status.getStatus().toUpperCase() + Const.CR ).toString(); }
public StringBuffer getBuffer( String parentLogChannelId, boolean includeGeneral, int startLineNr ) { return getBuffer( parentLogChannelId, includeGeneral, startLineNr, getLastBufferLineNr() ); }
KettleLogStore.getAppender().addLoggingEventListener( fileAppender ); } else { fileAppender = null; if ( fileAppender != null ) { fileAppender.close(); KettleLogStore.getAppender().removeLoggingEventListener( fileAppender );
public void dispose() { KettleLogStore.getAppender().removeLoggingEventListener( this ); }
public StringBuffer getBuffer( String parentLogChannelId, boolean includeGeneral, int startLineNr, int endLineNr ) { StringBuilder eventBuffer = new StringBuilder( 10000 ); List<KettleLoggingEvent> events = getLogBufferFromTo( parentLogChannelId, includeGeneral, startLineNr, endLineNr ); for ( KettleLoggingEvent event : events ) { eventBuffer.append( layout.format( event ) ).append( Const.CR ); } return new StringBuffer( eventBuffer ); }
/** * Discard all the lines for the specified log channel id AND all the children. * * @param parentLogChannelId * the parent log channel id to be removed along with all its children. */ public static void discardLines( String parentLogChannelId, boolean includeGeneralMessages ) { LoggingRegistry registry = LoggingRegistry.getInstance(); MetricsRegistry metricsRegistry = MetricsRegistry.getInstance(); List<String> ids = registry.getLogChannelChildren( parentLogChannelId ); // Remove all the rows for these ids // LoggingBuffer bufferAppender = getInstance().appender; // int beforeSize = bufferAppender.size(); for ( String id : ids ) { // Remove it from the central log buffer // bufferAppender.removeChannelFromBuffer( id ); // Also remove the item from the registry. // registry.getMap().remove( id ); metricsRegistry.getSnapshotLists().remove( id ); metricsRegistry.getSnapshotMaps().remove( id ); } // Now discard the general lines if this is required // if ( includeGeneralMessages ) { bufferAppender.removeGeneralMessages(); } }
/** * Initialize the central log store. If it has already been initialized the configuration will be updated. * * @param maxSize * the maximum size of the log buffer * @param maxLogTimeoutMinutes * The maximum time that a log line times out in minutes */ private static synchronized void init0( int maxSize, int maxLogTimeoutMinutes, boolean redirectStdOut, boolean redirectStdErr ) { if ( store != null ) { // CentralLogStore already initialized. Just update the values. store.appender.setMaxNrLines( maxSize ); store.replaceLogCleaner( maxLogTimeoutMinutes ); } else { store = new KettleLogStore( maxSize, maxLogTimeoutMinutes, redirectStdOut, redirectStdErr ); } initialized.set( true ); }
@Override Void doCall() { for ( int i = 0; i < 5000; i++ ) { buffer.addLogggingEvent( new KettleLoggingEvent( new LogMessage( "subject", LogLevel.DEBUG ), System.currentTimeMillis(), LogLevel.DEBUG ) ); } return null; } }
/** * Create the central log store with optional limitation to the size * * @param maxSize * the maximum size * @param maxLogTimeoutMinutes * The maximum time that a log line times out in Minutes. */ private KettleLogStore( int maxSize, int maxLogTimeoutMinutes, boolean redirectStdOut, boolean redirectStdErr ) { this.appender = new LoggingBuffer( maxSize ); replaceLogCleaner( maxLogTimeoutMinutes ); if ( redirectStdOut ) { System.setOut( new LoggingPrintStream( OriginalSystemOut ) ); } if ( redirectStdErr ) { System.setErr( new LoggingPrintStream( OriginalSystemErr ) ); } }
KettleLogStore.getAppender().addLoggingEventListener( loggingEventListener ); } catch ( KettleException e ) { logError( BaseMessages.getString( PKG, "JobEntryShell.Error.UnableopenAppenderFile", getLogFilename(), e KettleLogStore.getAppender().removeLoggingEventListener( loggingEventListener ); loggingEventListener.close();
private static final void exitJVM( int status ) { // Let's not forget to close the log file we're writing to... // if ( fileLoggingEventListener != null ) { try { fileLoggingEventListener.close(); } catch ( Exception e ) { e.printStackTrace( System.err ); status = 1; } KettleLogStore.getAppender().removeLoggingEventListener( fileLoggingEventListener ); } System.exit( status ); }
/** * Get all the log lines for the specified parent log channel id (including all children) * * @param channelId * channel IDs to grab * @param includeGeneral * include general log lines * @param from * @param to * @return */ public static List<KettleLoggingEvent> getLogBufferFromTo( List<String> channelId, boolean includeGeneral, int from, int to ) { return getInstance().appender.getLogBufferFromTo( channelId, includeGeneral, from, to ); }
public void loadSettings() { LogLevel logLevel = LogLevel.getLogLevelForCode( props.getLogLevel() ); DefaultLogLevel.setLogLevel( logLevel ); log.setLogLevel( logLevel ); KettleLogStore.getAppender().setMaxNrLines( props.getMaxNrLinesInLog() ); // transMeta.setMaxUndo(props.getMaxUndo()); DBCache.getInstance().setActive( props.useDBCache() ); }
KettleLogStore.getAppender().addLogggingEvent( loggingEvent );
@Test public void shouldNotFailProcessingEventsUnderHighContention() throws Exception { int modifiersAmount = 100; int readersAmount = 100; buffer = new LoggingBuffer( 5000 ); AtomicBoolean condition = new AtomicBoolean( true ); List<StopOnErrorCallable<?>> modifiers = new ArrayList<>(); for ( int i = 0; i < modifiersAmount; i++ ) { modifiers.add( new Appender( condition ) ); } List<StopOnErrorCallable<?>> readers = new ArrayList<>(); for ( int i = 0; i < readersAmount; i++ ) { readers.add( new Reader( condition ) ); } ConcurrencyTestRunner<?, ?> runner = new ConcurrencyTestRunner<>( modifiers, readers, condition, 5000 ); runner.runConcurrentTest(); runner.checkNoExceptionRaised(); }
public StringBuffer getBuffer() { return getBuffer( null, true ); }
@Test public void testRemoveChannelFromBufferCallInGetLogBufferInFirstJobExecution() { StringBuffer sb = new StringBuffer( "" ); LoggingBuffer lb = mock( LoggingBuffer.class ); doReturn( sb ).when( lb ).getBuffer( anyString(), anyBoolean() ); mockStatic( KettleLogStore.class ); mockStatic( Utils.class ); mockStatic( Const.class ); when( KettleLogStore.getAppender() ).thenReturn( lb ); BaseLogTable baseLogTable = mock( BaseLogTable.class ); doCallRealMethod().when( baseLogTable ).getLogBuffer( any( VariableSpace.class ), anyString(), any( LogStatus.class ), anyString() ); VariableSpace vs = mock( VariableSpace.class ); String s1 = baseLogTable.getLogBuffer( vs, "1", LogStatus.START, null ); String s2 = baseLogTable.getLogBuffer( vs, "1", LogStatus.END, null ); assertEquals( Const.CR + "START" + Const.CR, s1 ); assertEquals( Const.CR + "START" + Const.CR, s1 + Const.CR + "END" + Const.CR, s2 ); verify( lb, times( 1 ) ).removeChannelFromBuffer( "1" ); }
KettleLogStore.getAppender().addLoggingEventListener( new ConsoleLoggingEventListener() ); KettleLogStore.getAppender().addLoggingEventListener( new Slf4jLoggingEventListener() );