org.gradle.internal.logging.services.LoggingServiceRegistry Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of gradle-api Show documentation
Show all versions of gradle-api Show documentation
Gradle 6.9.1 API redistribution.
/*
* Copyright 2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.gradle.internal.logging.services;
import org.gradle.api.logging.configuration.LoggingConfiguration;
import org.gradle.cli.CommandLineConverter;
import org.gradle.internal.TimeProvider;
import org.gradle.internal.TrueTimeProvider;
import org.gradle.internal.logging.LoggingCommandLineConverter;
import org.gradle.internal.logging.LoggingManagerInternal;
import org.gradle.internal.logging.config.LoggingSourceSystem;
import org.gradle.internal.logging.config.LoggingSystemAdapter;
import org.gradle.internal.logging.events.OutputEventListener;
import org.gradle.internal.logging.progress.DefaultProgressLoggerFactory;
import org.gradle.internal.logging.progress.ProgressLoggerFactory;
import org.gradle.internal.logging.sink.OutputEventRenderer;
import org.gradle.internal.logging.slf4j.Slf4jLoggingConfigurer;
import org.gradle.internal.logging.source.DefaultStdErrLoggingSystem;
import org.gradle.internal.logging.source.DefaultStdOutLoggingSystem;
import org.gradle.internal.logging.source.JavaUtilLoggingSystem;
import org.gradle.internal.logging.source.NoOpLoggingSystem;
import org.gradle.internal.logging.text.StyledTextOutputFactory;
import org.gradle.internal.service.DefaultServiceRegistry;
/**
* A {@link org.gradle.internal.service.ServiceRegistry} implementation that provides the logging services. To use this:
*
*
* - Create an instance using one of the static factory methods below.
* - Create an instance of {@link LoggingManagerInternal}.
* - Configure the logging manager as appropriate.
* - Start the logging manager using {@link LoggingManagerInternal#start()}.
* - When finished, stop the logging manager using {@link LoggingManagerInternal#stop()}.
*
*/
public abstract class LoggingServiceRegistry extends DefaultServiceRegistry {
private TextStreamOutputEventListener stdoutListener;
/**
* Creates a set of logging services which are suitable to use globally in a process. In particular:
*
*
* - Replaces System.out and System.err with implementations that route output through the logging system as per {@link LoggingManagerInternal#captureSystemSources()}.
* - Configures slf4j, log4j and java util logging to route log messages through the logging system.
* - Routes logging output to the original System.out and System.err as per {@link LoggingManagerInternal#attachSystemOutAndErr()}.
* - Sets log level to {@link org.gradle.api.logging.LogLevel#LIFECYCLE}.
*
*
* Does nothing until started.
*
* Allows dynamic and colored output to be written to the console. Use {@link LoggingManagerInternal#attachProcessConsole(org.gradle.api.logging.configuration.ConsoleOutput)} to enable this.
*/
public static LoggingServiceRegistry newCommandLineProcessLogging() {
CommandLineLogging loggingServices = new CommandLineLogging();
LoggingManagerInternal rootLoggingManager = loggingServices.get(DefaultLoggingManagerFactory.class).getRoot();
rootLoggingManager.captureSystemSources();
rootLoggingManager.attachSystemOutAndErr();
return loggingServices;
}
/**
* Creates a set of logging services which are suitable to use embedded in another application. In particular:
*
*
* - Configures slf4j and log4j to route log messages through the logging system.
* - Sets log level to {@link org.gradle.api.logging.LogLevel#LIFECYCLE}.
*
*
* Does not:
*
*
* - Replace System.out and System.err to capture output written to these destinations. Use {@link LoggingManagerInternal#captureSystemSources()} to enable this.
* - Configure java util logging. Use {@link LoggingManagerInternal#captureSystemSources()} to enable this.
* - Route logging output to the original System.out and System.err. Use {@link LoggingManagerInternal#attachSystemOutAndErr()} to enable this.
*
*
* Does nothing until started.
*/
public static LoggingServiceRegistry newEmbeddableLogging() {
return new CommandLineLogging();
}
/**
* Creates a set of logging services to set up a new logging scope that does nothing by default. The methods on {@link LoggingManagerInternal} can be used to configure the
* logging services do useful things.
*
* Sets log level to {@link org.gradle.api.logging.LogLevel#LIFECYCLE}.
*/
public static LoggingServiceRegistry newNestedLogging() {
return new NestedLogging();
}
protected CommandLineConverter createCommandLineConverter() {
return new LoggingCommandLineConverter();
}
protected TimeProvider createTimeProvider() {
return new TrueTimeProvider();
}
protected StyledTextOutputFactory createStyledTextOutputFactory() {
return new DefaultStyledTextOutputFactory(getStdoutListener(), get(TimeProvider.class));
}
protected TextStreamOutputEventListener getStdoutListener() {
if (stdoutListener == null) {
stdoutListener = new TextStreamOutputEventListener(get(OutputEventListener.class));
}
return stdoutListener;
}
protected ProgressLoggerFactory createProgressLoggerFactory() {
return new DefaultProgressLoggerFactory(new ProgressLoggingBridge(get(OutputEventListener.class)), get(TimeProvider.class));
}
protected DefaultLoggingManagerFactory createLoggingManagerFactory() {
OutputEventRenderer renderer = get(OutputEventRenderer.class);
LoggingSourceSystem stdout = new DefaultStdOutLoggingSystem(getStdoutListener(), get(TimeProvider.class));
LoggingSourceSystem stderr = new DefaultStdErrLoggingSystem(new TextStreamOutputEventListener(get(OutputEventListener.class)), get(TimeProvider.class));
return new DefaultLoggingManagerFactory(
renderer,
new LoggingSystemAdapter(new Slf4jLoggingConfigurer(renderer)),
new JavaUtilLoggingSystem(),
stdout,
stderr);
}
protected OutputEventRenderer createOutputEventRenderer() {
return new OutputEventRenderer();
}
private static class CommandLineLogging extends LoggingServiceRegistry {
}
private static class NestedLogging extends LoggingServiceRegistry {
protected DefaultLoggingManagerFactory createLoggingManagerFactory() {
OutputEventRenderer renderer = get(OutputEventRenderer.class);
// Don't configure anything
return new DefaultLoggingManagerFactory(renderer,
new NoOpLoggingSystem(),
new NoOpLoggingSystem(),
new NoOpLoggingSystem(),
new NoOpLoggingSystem());
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy