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 LogChannel( Object subject ) { logLevel = DefaultLogLevel.getLogLevel(); logChannelId = LoggingRegistry.getInstance().registerLoggingSource( subject ); }
/** * Gets the logging hierarchy. * * @return the logging hierarchy */ public List<LoggingHierarchy> getLoggingHierarchy() { List<LoggingHierarchy> hierarchy = new ArrayList<>(); List<String> childIds = LoggingRegistry.getInstance().getLogChannelChildren( getLogChannelId() ); for ( String childId : childIds ) { LoggingObjectInterface loggingObject = LoggingRegistry.getInstance().getLoggingObject( childId ); if ( loggingObject != null ) { hierarchy.add( new LoggingHierarchy( getLogChannelId(), batchId, loggingObject ) ); } } return hierarchy; }
/** * Gets the logging hierarchy. * * @return the logging hierarchy */ public List<LoggingHierarchy> getLoggingHierarchy() { List<LoggingHierarchy> hierarchy = new ArrayList<LoggingHierarchy>(); List<String> childIds = LoggingRegistry.getInstance().getLogChannelChildren( getLogChannelId() ); for ( String childId : childIds ) { LoggingObjectInterface loggingObject = LoggingRegistry.getInstance().getLoggingObject( childId ); if ( loggingObject != null ) { hierarchy.add( new LoggingHierarchy( getLogChannelId(), batchId, loggingObject ) ); } } return hierarchy; }
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() ); } }
@VisibleForTesting void discardLogLines( TransExecutorData transExecutorData ) { // Keep the strain on the logging back-end conservative. // TODO: make this optional/user-defined later Trans executorTrans = transExecutorData.getExecutorTrans(); if ( executorTrans != null ) { KettleLogStore.discardLines( executorTrans.getLogChannelId(), false ); LoggingRegistry.getInstance().removeIncludingChildren( executorTrans.getLogChannelId() ); } }
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 ); }
/** * 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 ); }
@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 ); } }
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(); } }
@Override public void mouseDown( MouseEvent event ) { if ( drawAreas == null ) { return; } for ( int i = drawAreas.size() - 1; i >= 0; i-- ) { MetricsDrawArea drawArea = drawAreas.get( i ); if ( drawArea.getArea().contains( event.x, event.y ) ) { MetricsDuration duration = drawArea.getDuration(); if ( duration == null ) { continue; } System.out.println( duration.toString() ); LoggingObjectInterface loggingObject = LoggingRegistry.getInstance().getLoggingObject( duration.getLogChannelId() ); if ( loggingObject == null ) { return; } System.out.println( loggingObject.getObjectType() + " : " + loggingObject.getObjectName() ); } } } } );
@Override public void mouseDown( MouseEvent event ) { if ( drawAreas == null ) { return; } for ( int i = drawAreas.size() - 1; i >= 0; i-- ) { MetricsDrawArea drawArea = drawAreas.get( i ); if ( drawArea.getArea().contains( event.x, event.y ) ) { MetricsDuration duration = drawArea.getDuration(); if ( duration == null ) { continue; } System.out.println( duration.toString() ); LoggingObjectInterface loggingObject = LoggingRegistry.getInstance().getLoggingObject( duration.getLogChannelId() ); if ( loggingObject == null ) { continue; } System.out.println( loggingObject.getObjectType() + " : " + loggingObject.getObjectName() ); } } } } );
LoggingRegistry.getInstance().getLoggingObject( parent.getLogChannelId() ); if ( parentLoggingObject != null ) { parent = parentLoggingObject; LoggingRegistry registry = LoggingRegistry.getInstance();
/** * 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(); } }
@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(); }
@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 ) ); }
LogChannelFileWriterBuffer fileWriter = LoggingRegistry.getInstance().getLogChannelFileWriterBuffer( logChannelId ); if ( fileWriter != null ) { fileWriter.addEvent( loggingEvent );
LoggingRegistry.getInstance().removeIncludingChildren( trans.getLogChannelId() ); KettleLogStore.discardLines( trans.getLogChannelId(), false ); LoggingRegistry.getInstance().removeLogChannelFileWriterBuffer( id );
private void drawDurations( List<MetricsDuration> durations, List<MetricsDrawArea> areas, double pixelsPerMs ) { // set top indent int y = 20; for ( MetricsDuration duration : durations ) { Long realDuration = duration.getEndDate().getTime() - duration.getDate().getTime(); // How many pixels does it take to drawn this duration? // int durationWidth = (int) ( realDuration * pixelsPerMs ); int x = 2 + (int) ( ( duration.getDate().getTime() - periodStart ) * pixelsPerMs ); getGc().setBackground( EColor.BACKGROUND ); getGc().setForeground( EColor.LIGHTBLUE ); getGc().fillGradientRectangle( x, y, durationWidth, barHeight, false ); getGc().setForeground( EColor.BLACK ); getGc().drawRectangle( x, y, durationWidth, barHeight ); areas.add( new MetricsDrawArea( new Rectangle( x, y, durationWidth, barHeight ), duration ) ); LoggingObjectInterface loggingObject = LoggingRegistry.getInstance().getLoggingObject( duration.getLogChannelId() ); String message = duration.getDescription() + " - " + loggingObject.getObjectName() + " : " + duration.getDuration() + "ms"; if ( duration.getCount() > 1 ) { message += " " + duration.getCount() + " calls, avg=" + ( duration.getDuration() / duration.getCount() ); } getGc().setFont( EFont.GRAPH ); getGc().textExtent( message ); getGc().drawText( message, x + 3, y + 4, true ); y += barHeight + 5; } }