public static List<MetricsDuration> getAllDurations( String parentLogChannelId ) { List<MetricsDuration> durations = new ArrayList<MetricsDuration>(); List<String> logChannelIds = LoggingRegistry.getInstance().getLogChannelChildren( parentLogChannelId ); for ( String logChannelId : logChannelIds ) { LoggingObjectInterface object = LoggingRegistry.getInstance().getLoggingObject( logChannelId ); if ( object != null ) { durations.addAll( getDurations( logChannelId ) ); } } return durations; }
public void dumpLoggingRegistry() { LoggingRegistry registry = LoggingRegistry.getInstance(); Map<String, LoggingObjectInterface> loggingMap = registry.getMap(); for ( LoggingObjectInterface loggingObject : loggingMap.values() ) { System.out.println( loggingObject.getLogChannelId() + " - " + loggingObject.getObjectName() + " - " + loggingObject.getObjectType() ); } }
@VisibleForTesting void discardLogLines( JobExecutorData data ) { // Keep the strain on the logging back-end conservative. // TODO: make this optional/user-defined later if ( data.executorJob != null ) { KettleLogStore.discardLines( data.executorJob.getLogChannelId(), false ); LoggingRegistry.getInstance().removeIncludingChildren( data.executorJob.getLogChannelId() ); } }
public void removeIncludingChildren( String logChannelId ) { synchronized ( this.map ) { List<String> children = getLogChannelChildren( logChannelId ); for ( String child : children ) { this.map.remove( child ); } this.map.remove( logChannelId ); removeOrphans(); } }
public LogChannel( Object subject ) { logLevel = DefaultLogLevel.getLogLevel(); logChannelId = LoggingRegistry.getInstance().registerLoggingSource( subject ); }
private void lookupSubject() { // Derive the subject from the registry // LoggingObjectInterface loggingObject = LoggingRegistry.getInstance().getLoggingObject( logChannelId ); boolean detailedLogTurnOn = "Y".equals( EnvUtil.getSystemProperty( Const.KETTLE_LOG_MARK_MAPPINGS ) ) ? true : false; if ( loggingObject != null ) { if ( !detailedLogTurnOn ) { subject = loggingObject.getObjectName(); } else { subject = getDetailedSubject( loggingObject ); } copy = loggingObject.getObjectCopy(); } }
LoggingRegistry.getInstance().getLoggingObject( parent.getLogChannelId() ); if ( parentLoggingObject != null ) { parent = parentLoggingObject; LoggingRegistry registry = LoggingRegistry.getInstance(); LoggingObjectInterface loggingObject = registry.findExistingLoggingSource( check ); if ( loggingObject == null ) { String logChannelId = registry.registerLoggingSource( check ); loggingObject = check; check.setLogChannelId( logChannelId );
/** * 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(); } }
@Test public void test() throws Exception { LogChannelFileWriter writer = new LogChannelFileWriter( id, fileObject, false ); LoggingRegistry.getInstance().getLogChannelFileWriterBuffer( id ).addEvent( new KettleLoggingEvent( logMessage, System.currentTimeMillis(), LogLevel.BASIC ) ); writer.flush(); verify( outputStream ).write( captor.capture() ); String arguments = new String( captor.getValue() ); assertTrue( arguments.contains( logMessage ) ); }
@Override public void eventAdded( KettleLoggingEvent event ) { try { Object messageObject = event.getMessage(); if ( messageObject instanceof LogMessage ) { boolean logToFile = false; if ( logChannelId == null ) { logToFile = true; } else { LogMessage message = (LogMessage) messageObject; // This should be fast enough cause cached. List<String> logChannelChildren = LoggingRegistry.getInstance().getLogChannelChildren( logChannelId ); // This could be non-optimal, consider keeping the list sorted in the logging registry logToFile = Const.indexOfString( message.getLogChannelId(), logChannelChildren ) >= 0; } if ( logToFile ) { String logText = layout.format( event ); outputStream.write( logText.getBytes() ); outputStream.write( Const.CR.getBytes() ); } } } catch ( Exception e ) { exception = new KettleException( "Unable to write to logging event to file '" + filename + "'", e ); } }
LoggingRegistry.getInstance().removeIncludingChildren( trans.getLogChannelId() ); KettleLogStore.discardLines( trans.getLogChannelId(), false ); LoggingRegistry.getInstance().removeLogChannelFileWriterBuffer( id );
/** * Create a new log channel file writer * * @param logChannelId * The log channel (+children) to write to the log file * @param logFile * The logging file to write to * @param appending * set to true if you want to append to an existing file * @param pollingInterval * The polling interval in milliseconds. * * @throws KettleException * in case the specified log file can't be created. */ public LogChannelFileWriter( String logChannelId, FileObject logFile, boolean appending, int pollingInterval ) throws KettleException { this.logChannelId = logChannelId; this.logFile = logFile; this.appending = appending; this.pollingInterval = pollingInterval; active = new AtomicBoolean( false ); finished = new AtomicBoolean( false ); try { logFileOutputStream = KettleVFS.getOutputStream( logFile, appending ); } catch ( IOException e ) { throw new KettleException( "There was an error while trying to open file '" + logFile + "' for writing", e ); } this.buffer = new LogChannelFileWriterBuffer( this.logChannelId ); LoggingRegistry.getInstance().registerLogChannelFileWriterBuffer( this.buffer ); }
public void removeLogChannelFileWriterBuffer( String id ) { Set<String> bufferIds = this.fileWriterBuffers.keySet(); for ( String bufferId : bufferIds ) { if ( getLogChannelChildren( id ).contains( bufferId ) ) { this.fileWriterBuffers.remove( bufferId ); } } }
private boolean isGeneral( String logChannelId ) { LoggingObjectInterface loggingObject = loggingRegistry.getLoggingObject( logChannelId ); return loggingObject != null && LoggingObjectType.GENERAL.equals( loggingObject.getObjectType() ); }
LoggingObjectInterface found = findExistingLoggingSource( loggingSource ); if ( found != null ) { LoggingObjectInterface foundParent = found.getParent(); Set<String> channelsNotToRemove = getLogChannelFileWriterBufferIds(); for ( int i = 0; i < cutCount; i++ ) { LoggingObjectInterface toRemove = all.get( i ); removeOrphans();
@Override public String toString() { LoggingObjectInterface loggingObject = LoggingRegistry.getInstance().getLoggingObject( logChannelId ); String subject = null; if ( loggingObject != null ) { subject = loggingObject.getObjectName() + "(" + loggingObject.getObjectType() + ")"; } else { subject = "-"; } return subject + " - " + getKey() + " @ " + StringUtil.getFormattedDateTime( date, true ) + " : " + type.toString(); }
LogChannelFileWriterBuffer fileWriter = LoggingRegistry.getInstance().getLogChannelFileWriterBuffer( logChannelId ); if ( fileWriter != null ) { fileWriter.addEvent( loggingEvent );
db.setCommit( logCommitSize ); List<String> logChannelIds = LoggingRegistry.getInstance().getLogChannelChildren( getLogChannelId() ); for ( String logChannelId : logChannelIds ) { Queue<MetricsSnapshotInterface> snapshotList =
public LogChannel( Object subject, LoggingObjectInterface parentObject ) { if ( parentObject != null ) { this.logLevel = parentObject.getLogLevel(); this.containerObjectId = parentObject.getContainerObjectId(); } else { this.logLevel = DefaultLogLevel.getLogLevel(); this.containerObjectId = null; } logChannelId = LoggingRegistry.getInstance().registerLoggingSource( subject ); }
public List<String> getLogChannelChildren( String parentLogChannelId ) { if ( parentLogChannelId == null ) { return null; } List<String> list = getLogChannelChildren( new ArrayList<String>(), parentLogChannelId ); list.add( parentLogChannelId ); return list; }