Search in sources :

Example 1 with StandardOutputListener

use of org.gradle.api.logging.StandardOutputListener in project gradle by gradle.

the class DefaultLoggingManager method stop.

@Override
public DefaultLoggingManager stop() {
    try {
        CompositeStoppable.stoppable(slf4jLoggingSystem, javaUtilLoggingSystem, stdOutLoggingSystem, stdErrLoggingSystem).stop();
        for (StandardOutputListener stdoutListener : stdoutListeners) {
            loggingOutput.removeStandardOutputListener(stdoutListener);
        }
        for (StandardOutputListener stderrListener : stderrListeners) {
            loggingOutput.removeStandardErrorListener(stderrListener);
        }
        for (OutputEventListener listener : outputEventListeners) {
            loggingOutput.removeOutputEventListener(listener);
        }
        loggingRouter.stop();
    } finally {
        started = false;
    }
    return this;
}
Also used : StreamBackedStandardOutputListener(org.gradle.internal.logging.text.StreamBackedStandardOutputListener) StandardOutputListener(org.gradle.api.logging.StandardOutputListener) OutputEventListener(org.gradle.internal.logging.events.OutputEventListener)

Example 2 with StandardOutputListener

use of org.gradle.api.logging.StandardOutputListener in project gradle by gradle.

the class DefaultGradleLauncherFactory method doNewInstance.

private DefaultGradleLauncher doNewInstance(StartParameter startParameter, GradleLauncher parent, BuildCancellationToken cancellationToken, BuildRequestMetaData requestMetaData, BuildEventConsumer buildEventConsumer, final BuildSessionScopeServices sessionScopeServices, List<?> servicesToStop) {
    BuildScopeServices serviceRegistry = BuildScopeServices.forSession(sessionScopeServices);
    serviceRegistry.add(BuildRequestMetaData.class, requestMetaData);
    serviceRegistry.add(BuildClientMetaData.class, requestMetaData.getClient());
    serviceRegistry.add(BuildEventConsumer.class, buildEventConsumer);
    serviceRegistry.add(BuildCancellationToken.class, cancellationToken);
    NestedBuildFactoryImpl nestedBuildFactory = new NestedBuildFactoryImpl(sessionScopeServices);
    serviceRegistry.add(NestedBuildFactory.class, nestedBuildFactory);
    ListenerManager listenerManager = serviceRegistry.get(ListenerManager.class);
    LoggingManagerInternal loggingManager = serviceRegistry.newInstance(LoggingManagerInternal.class);
    loggingManager.setLevelInternal(startParameter.getLogLevel());
    //this hooks up the ListenerManager and LoggingConfigurer so you can call Gradle.addListener() with a StandardOutputListener.
    loggingManager.addStandardOutputListener(listenerManager.getBroadcaster(StandardOutputListener.class));
    loggingManager.addStandardErrorListener(listenerManager.getBroadcaster(StandardOutputListener.class));
    LoggerProvider loggerProvider = (parent == null) ? buildProgressLogger : LoggerProvider.NO_OP;
    listenerManager.useLogger(new TaskExecutionLogger(serviceRegistry.get(ProgressLoggerFactory.class), loggerProvider));
    if (parent == null) {
        listenerManager.useLogger(new BuildLogger(Logging.getLogger(BuildLogger.class), serviceRegistry.get(StyledTextOutputFactory.class), startParameter, requestMetaData));
    }
    if (startParameter.isBuildCacheEnabled()) {
        listenerManager.addListener(serviceRegistry.get(TaskExecutionStatisticsEventAdapter.class));
        listenerManager.addListener(new CacheStatisticsReporter(serviceRegistry.get(StyledTextOutputFactory.class)));
    }
    listenerManager.addListener(serviceRegistry.get(ProfileEventAdapter.class));
    if (startParameter.isProfile()) {
        listenerManager.addListener(new ReportGeneratingProfileListener(serviceRegistry.get(StyledTextOutputFactory.class)));
    }
    BuildScanRequest buildScanRequest = serviceRegistry.get(BuildScanRequest.class);
    if (startParameter.isBuildScan()) {
        if (!startParameter.getSystemPropertiesArgs().containsKey("scan")) {
            startParameter.getSystemPropertiesArgs().put("scan", "true");
        }
        buildScanRequest.markRequested();
        listenerManager.addListener(new BuildScanRequestListener());
    }
    if (startParameter.isNoBuildScan()) {
        if (!startParameter.getSystemPropertiesArgs().containsKey("scan")) {
            startParameter.getSystemPropertiesArgs().put("scan", "false");
        }
        buildScanRequest.markDisabled();
    }
    ScriptUsageLocationReporter usageLocationReporter = new ScriptUsageLocationReporter();
    listenerManager.addListener(usageLocationReporter);
    BuildOutputCleanupListener buildOutputCleanupListener = serviceRegistry.get(BuildOutputCleanupListener.class);
    listenerManager.addListener(buildOutputCleanupListener);
    ShowStacktrace showStacktrace = startParameter.getShowStacktrace();
    switch(showStacktrace) {
        case ALWAYS:
        case ALWAYS_FULL:
            LoggingDeprecatedFeatureHandler.setTraceLoggingEnabled(true);
            break;
        default:
            LoggingDeprecatedFeatureHandler.setTraceLoggingEnabled(false);
    }
    DeprecationLogger.useLocationReporter(usageLocationReporter);
    SettingsLoaderFactory settingsLoaderFactory = serviceRegistry.get(SettingsLoaderFactory.class);
    SettingsLoader settingsLoader = parent != null ? settingsLoaderFactory.forNestedBuild() : settingsLoaderFactory.forTopLevelBuild();
    GradleInternal parentBuild = parent == null ? null : parent.getGradle();
    GradleInternal gradle = serviceRegistry.get(Instantiator.class).newInstance(DefaultGradle.class, parentBuild, startParameter, serviceRegistry.get(ServiceRegistryFactory.class));
    DefaultGradleLauncher gradleLauncher = new DefaultGradleLauncher(gradle, serviceRegistry.get(InitScriptHandler.class), settingsLoader, serviceRegistry.get(BuildConfigurer.class), serviceRegistry.get(ExceptionAnalyser.class), loggingManager, gradle.getBuildListenerBroadcaster(), listenerManager.getBroadcaster(ModelConfigurationListener.class), listenerManager.getBroadcaster(BuildCompletionListener.class), serviceRegistry.get(BuildOperationExecutor.class), gradle.getServices().get(BuildConfigurationActionExecuter.class), gradle.getServices().get(BuildExecuter.class), serviceRegistry, servicesToStop);
    nestedBuildFactory.setParent(gradleLauncher);
    return gradleLauncher;
}
Also used : CacheStatisticsReporter(org.gradle.internal.buildevents.CacheStatisticsReporter) ExceptionAnalyser(org.gradle.api.internal.ExceptionAnalyser) BuildScanRequestListener(org.gradle.internal.scan.BuildScanRequestListener) Instantiator(org.gradle.internal.reflect.Instantiator) GradleInternal(org.gradle.api.internal.GradleInternal) StandardOutputListener(org.gradle.api.logging.StandardOutputListener) ReportGeneratingProfileListener(org.gradle.profile.ReportGeneratingProfileListener) BuildExecuter(org.gradle.execution.BuildExecuter) LoggerProvider(org.gradle.internal.progress.LoggerProvider) ScriptUsageLocationReporter(org.gradle.internal.featurelifecycle.ScriptUsageLocationReporter) BuildConfigurer(org.gradle.configuration.BuildConfigurer) LoggingManagerInternal(org.gradle.internal.logging.LoggingManagerInternal) BuildConfigurationActionExecuter(org.gradle.execution.BuildConfigurationActionExecuter) ProfileEventAdapter(org.gradle.profile.ProfileEventAdapter) BuildScopeServices(org.gradle.internal.service.scopes.BuildScopeServices) TaskExecutionStatisticsEventAdapter(org.gradle.caching.internal.tasks.TaskExecutionStatisticsEventAdapter) BuildScanRequest(org.gradle.internal.scan.BuildScanRequest) ShowStacktrace(org.gradle.api.logging.configuration.ShowStacktrace) BuildOperationExecutor(org.gradle.internal.progress.BuildOperationExecutor) ServiceRegistryFactory(org.gradle.internal.service.scopes.ServiceRegistryFactory) BuildOutputCleanupListener(org.gradle.internal.cleanup.BuildOutputCleanupListener) TaskExecutionLogger(org.gradle.internal.buildevents.TaskExecutionLogger) BuildLogger(org.gradle.internal.buildevents.BuildLogger) ListenerManager(org.gradle.internal.event.ListenerManager)

Example 3 with StandardOutputListener

use of org.gradle.api.logging.StandardOutputListener in project gradle by gradle.

the class DefaultLoggingManager method start.

@Override
public DefaultLoggingManager start() {
    started = true;
    if (enableStdOutListeners) {
        loggingRouter.loggingRouter.enableUserStandardOutputListeners();
    }
    for (StandardOutputListener stdoutListener : stdoutListeners) {
        loggingOutput.addStandardOutputListener(stdoutListener);
    }
    for (StandardOutputListener stderrListener : stderrListeners) {
        loggingOutput.addStandardErrorListener(stderrListener);
    }
    for (OutputEventListener outputEventListener : outputEventListeners) {
        loggingOutput.addOutputEventListener(outputEventListener);
    }
    loggingRouter.start();
    slf4jLoggingSystem.enableCapture();
    slf4jLoggingSystem.start();
    javaUtilLoggingSystem.start();
    stdOutLoggingSystem.start();
    stdErrLoggingSystem.start();
    return this;
}
Also used : StreamBackedStandardOutputListener(org.gradle.internal.logging.text.StreamBackedStandardOutputListener) StandardOutputListener(org.gradle.api.logging.StandardOutputListener) OutputEventListener(org.gradle.internal.logging.events.OutputEventListener)

Example 4 with StandardOutputListener

use of org.gradle.api.logging.StandardOutputListener 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)

Aggregations

StandardOutputListener (org.gradle.api.logging.StandardOutputListener)4 OutputEventListener (org.gradle.internal.logging.events.OutputEventListener)3 StreamBackedStandardOutputListener (org.gradle.internal.logging.text.StreamBackedStandardOutputListener)3 ExceptionAnalyser (org.gradle.api.internal.ExceptionAnalyser)1 GradleInternal (org.gradle.api.internal.GradleInternal)1 ShowStacktrace (org.gradle.api.logging.configuration.ShowStacktrace)1 TaskExecutionStatisticsEventAdapter (org.gradle.caching.internal.tasks.TaskExecutionStatisticsEventAdapter)1 BuildConfigurer (org.gradle.configuration.BuildConfigurer)1 BuildConfigurationActionExecuter (org.gradle.execution.BuildConfigurationActionExecuter)1 BuildExecuter (org.gradle.execution.BuildExecuter)1 BuildLogger (org.gradle.internal.buildevents.BuildLogger)1 CacheStatisticsReporter (org.gradle.internal.buildevents.CacheStatisticsReporter)1 TaskExecutionLogger (org.gradle.internal.buildevents.TaskExecutionLogger)1 BuildOutputCleanupListener (org.gradle.internal.cleanup.BuildOutputCleanupListener)1 ListenerManager (org.gradle.internal.event.ListenerManager)1 ScriptUsageLocationReporter (org.gradle.internal.featurelifecycle.ScriptUsageLocationReporter)1 LoggingManagerInternal (org.gradle.internal.logging.LoggingManagerInternal)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