Search in sources :

Example 1 with RenderableOutputEvent

use of org.gradle.internal.logging.events.RenderableOutputEvent in project gradle by gradle.

the class LoggingBuildOperationProgressBroadcaster method onOutput.

@Override
public void onOutput(OutputEvent event) {
    if (event instanceof RenderableOutputEvent) {
        RenderableOutputEvent renderableOutputEvent = (RenderableOutputEvent) event;
        OperationIdentifier operationIdentifier = renderableOutputEvent.getBuildOperationId();
        if (operationIdentifier == null) {
            if (rootBuildOperation == null) {
                return;
            }
            operationIdentifier = rootBuildOperation;
        }
        if (renderableOutputEvent instanceof StyledTextOutputEvent || renderableOutputEvent instanceof LogEvent) {
            emit(renderableOutputEvent, operationIdentifier);
        }
    } else if (event instanceof ProgressStartEvent) {
        ProgressStartEvent progressStartEvent = (ProgressStartEvent) event;
        if (progressStartEvent.getLoggingHeader() == null) {
            // If the event has no logging header, it doesn't manifest as console output.
            return;
        }
        OperationIdentifier operationIdentifier = progressStartEvent.getBuildOperationId();
        if (operationIdentifier == null && rootBuildOperation != null) {
            operationIdentifier = rootBuildOperation;
        }
        emit(progressStartEvent, operationIdentifier);
    }
}
Also used : ProgressStartEvent(org.gradle.internal.logging.events.ProgressStartEvent) LogEvent(org.gradle.internal.logging.events.LogEvent) OperationIdentifier(org.gradle.internal.operations.OperationIdentifier) StyledTextOutputEvent(org.gradle.internal.logging.events.StyledTextOutputEvent) RenderableOutputEvent(org.gradle.internal.logging.events.RenderableOutputEvent)

Example 2 with RenderableOutputEvent

use of org.gradle.internal.logging.events.RenderableOutputEvent in project gradle by gradle.

the class OutputEventTransformer method onOutput.

@Override
public void onOutput(OutputEvent event) {
    if (event instanceof ProgressStartEvent) {
        ProgressStartEvent startEvent = (ProgressStartEvent) event;
        if (!startEvent.isBuildOperationStart()) {
            forwarded.add(startEvent.getProgressOperationId());
            OperationIdentifier parentProgressOperationId = startEvent.getParentProgressOperationId();
            if (parentProgressOperationId != null) {
                OperationIdentifier mappedId = effectiveProgressOperation.get(parentProgressOperationId);
                if (mappedId != null) {
                    startEvent = startEvent.withParentProgressOperation(mappedId);
                }
            }
            listener.onOutput(startEvent);
            return;
        }
        if (startEvent.getParentProgressOperationId() == null || GUtil.isTrue(startEvent.getLoggingHeader()) || GUtil.isTrue(startEvent.getStatus()) || startEvent.getBuildOperationCategory() != BuildOperationCategory.UNCATEGORIZED) {
            forwarded.add(startEvent.getProgressOperationId());
            OperationIdentifier parentProgressOperationId = startEvent.getParentProgressOperationId();
            if (parentProgressOperationId != null) {
                OperationIdentifier mappedId = effectiveProgressOperation.get(parentProgressOperationId);
                if (mappedId != null) {
                    startEvent = startEvent.withParentProgressOperation(mappedId);
                }
            }
            listener.onOutput(startEvent);
        } else {
            // Ignore this progress operation, and map any reference to it to its parent (or whatever its parent is mapped to)
            OperationIdentifier mappedParent = effectiveProgressOperation.get(startEvent.getParentProgressOperationId());
            if (mappedParent == null) {
                mappedParent = startEvent.getParentProgressOperationId();
            }
            effectiveProgressOperation.put(startEvent.getProgressOperationId(), mappedParent);
        }
    } else if (event instanceof ProgressCompleteEvent) {
        ProgressCompleteEvent completeEvent = (ProgressCompleteEvent) event;
        OperationIdentifier mappedEvent = effectiveProgressOperation.remove(completeEvent.getProgressOperationId());
        if (mappedEvent == null && forwarded.remove(completeEvent.getProgressOperationId())) {
            listener.onOutput(event);
        }
    } else if (event instanceof ProgressEvent) {
        ProgressEvent progressEvent = (ProgressEvent) event;
        if (forwarded.contains(progressEvent.getProgressOperationId())) {
            listener.onOutput(event);
        }
    } else if (event instanceof RenderableOutputEvent) {
        RenderableOutputEvent outputEvent = (RenderableOutputEvent) event;
        OperationIdentifier operationId = outputEvent.getBuildOperationId();
        if (operationId != null) {
            OperationIdentifier mappedId = effectiveProgressOperation.get(operationId);
            if (mappedId != null) {
                outputEvent = outputEvent.withBuildOperationId(mappedId);
            }
        }
        listener.onOutput(outputEvent);
    } else {
        listener.onOutput(event);
    }
}
Also used : ProgressStartEvent(org.gradle.internal.logging.events.ProgressStartEvent) OperationIdentifier(org.gradle.internal.operations.OperationIdentifier) ProgressCompleteEvent(org.gradle.internal.logging.events.ProgressCompleteEvent) RenderableOutputEvent(org.gradle.internal.logging.events.RenderableOutputEvent) ProgressEvent(org.gradle.internal.logging.events.ProgressEvent)

Example 3 with RenderableOutputEvent

use of org.gradle.internal.logging.events.RenderableOutputEvent in project gradle by gradle.

the class OutputEventRenderer method enableUserStandardOutputListeners.

@Override
public void enableUserStandardOutputListeners() {
    // Then, a pipeline can be added for each listener as required
    synchronized (lock) {
        if (userStdoutListeners == null) {
            userStdoutListeners = new ListenerBroadcast<StandardOutputListener>(StandardOutputListener.class);
            userStderrListeners = new ListenerBroadcast<StandardOutputListener>(StandardOutputListener.class);
            final OutputEventListener stdOutChain = new StyledTextOutputBackedRenderer(new StreamingStyledTextOutput(userStdoutListeners.getSource()));
            final OutputEventListener stdErrChain = new StyledTextOutputBackedRenderer(new StreamingStyledTextOutput(userStderrListeners.getSource()));
            userListenerChain = new BuildLogLevelFilterRenderer(new ProgressLogEventGenerator(new OutputEventListener() {

                @Override
                public void onOutput(OutputEvent event) {
                    // Do not forward events for rendering when there are no listeners to receive
                    if (event instanceof LogLevelChangeEvent) {
                        stdOutChain.onOutput(event);
                        stdErrChain.onOutput(event);
                    } else if (event.getLogLevel() == LogLevel.ERROR && !userStderrListeners.isEmpty() && event instanceof RenderableOutputEvent) {
                        stdErrChain.onOutput(event);
                    } else if (event.getLogLevel() != LogLevel.ERROR && !userStdoutListeners.isEmpty() && event instanceof RenderableOutputEvent) {
                        stdOutChain.onOutput(event);
                    }
                }
            }));
            addChain(userListenerChain);
        }
    }
}
Also used : LogLevelChangeEvent(org.gradle.internal.logging.events.LogLevelChangeEvent) OutputEvent(org.gradle.internal.logging.events.OutputEvent) EndOutputEvent(org.gradle.internal.logging.events.EndOutputEvent) RenderableOutputEvent(org.gradle.internal.logging.events.RenderableOutputEvent) FlushOutputEvent(org.gradle.internal.logging.events.FlushOutputEvent) StandardOutputListener(org.gradle.api.logging.StandardOutputListener) StreamBackedStandardOutputListener(org.gradle.internal.logging.text.StreamBackedStandardOutputListener) StyledTextOutputBackedRenderer(org.gradle.internal.logging.console.StyledTextOutputBackedRenderer) StreamingStyledTextOutput(org.gradle.internal.logging.text.StreamingStyledTextOutput) RenderableOutputEvent(org.gradle.internal.logging.events.RenderableOutputEvent) OutputEventListener(org.gradle.internal.logging.events.OutputEventListener) ThrottlingOutputEventListener(org.gradle.internal.logging.console.ThrottlingOutputEventListener) BuildLogLevelFilterRenderer(org.gradle.internal.logging.console.BuildLogLevelFilterRenderer)

Example 4 with RenderableOutputEvent

use of org.gradle.internal.logging.events.RenderableOutputEvent in project gradle by gradle.

the class StyledTextOutputBackedRenderer method onOutput.

@Override
public void onOutput(OutputEvent event) {
    if (event instanceof LogLevelChangeEvent) {
        LogLevelChangeEvent changeEvent = (LogLevelChangeEvent) event;
        boolean newLogLevelIsDebug = changeEvent.getNewLogLevel() == LogLevel.DEBUG;
        if (newLogLevelIsDebug && dateFormat == null) {
            dateFormat = new SimpleDateFormat(ISO_8601_DATE_TIME_FORMAT);
        }
        debugOutput = newLogLevelIsDebug;
    }
    if (event instanceof RenderableOutputEvent) {
        RenderableOutputEvent outputEvent = (RenderableOutputEvent) event;
        textOutput.style(outputEvent.getLogLevel() == LogLevel.ERROR ? Error : Normal);
        if (debugOutput && (textOutput.atEndOfLine || lastEvent == null || !lastEvent.getCategory().equals(outputEvent.getCategory()))) {
            if (!textOutput.atEndOfLine) {
                textOutput.println();
            }
            textOutput.text(dateFormat.format(new Date(outputEvent.getTimestamp())));
            textOutput.text(" [");
            textOutput.text(outputEvent.getLogLevel());
            textOutput.text("] [");
            textOutput.text(outputEvent.getCategory());
            textOutput.text("] ");
        }
        outputEvent.render(textOutput);
        lastEvent = outputEvent;
        textOutput.style(Normal);
    }
}
Also used : LogLevelChangeEvent(org.gradle.internal.logging.events.LogLevelChangeEvent) RenderableOutputEvent(org.gradle.internal.logging.events.RenderableOutputEvent) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date)

Aggregations

RenderableOutputEvent (org.gradle.internal.logging.events.RenderableOutputEvent)4 LogLevelChangeEvent (org.gradle.internal.logging.events.LogLevelChangeEvent)2 ProgressStartEvent (org.gradle.internal.logging.events.ProgressStartEvent)2 OperationIdentifier (org.gradle.internal.operations.OperationIdentifier)2 SimpleDateFormat (java.text.SimpleDateFormat)1 Date (java.util.Date)1 StandardOutputListener (org.gradle.api.logging.StandardOutputListener)1 BuildLogLevelFilterRenderer (org.gradle.internal.logging.console.BuildLogLevelFilterRenderer)1 StyledTextOutputBackedRenderer (org.gradle.internal.logging.console.StyledTextOutputBackedRenderer)1 ThrottlingOutputEventListener (org.gradle.internal.logging.console.ThrottlingOutputEventListener)1 EndOutputEvent (org.gradle.internal.logging.events.EndOutputEvent)1 FlushOutputEvent (org.gradle.internal.logging.events.FlushOutputEvent)1 LogEvent (org.gradle.internal.logging.events.LogEvent)1 OutputEvent (org.gradle.internal.logging.events.OutputEvent)1 OutputEventListener (org.gradle.internal.logging.events.OutputEventListener)1 ProgressCompleteEvent (org.gradle.internal.logging.events.ProgressCompleteEvent)1 ProgressEvent (org.gradle.internal.logging.events.ProgressEvent)1 StyledTextOutputEvent (org.gradle.internal.logging.events.StyledTextOutputEvent)1 StreamBackedStandardOutputListener (org.gradle.internal.logging.text.StreamBackedStandardOutputListener)1 StreamingStyledTextOutput (org.gradle.internal.logging.text.StreamingStyledTextOutput)1