Search in sources :

Example 1 with LoggingManagerInternal

use of org.gradle.internal.logging.LoggingManagerInternal in project gradle by gradle.

the class ProviderConnection method configure.

public void configure(ProviderConnectionParameters parameters) {
    LogLevel providerLogLevel = parameters.getVerboseLogging() ? LogLevel.DEBUG : LogLevel.INFO;
    LOGGER.debug("Configuring logging to level: {}", providerLogLevel);
    LoggingManagerInternal loggingManager = loggingServices.newInstance(LoggingManagerInternal.class);
    loggingManager.setLevelInternal(providerLogLevel);
    loggingManager.start();
}
Also used : LoggingManagerInternal(org.gradle.internal.logging.LoggingManagerInternal) LogLevel(org.gradle.api.logging.LogLevel)

Example 2 with LoggingManagerInternal

use of org.gradle.internal.logging.LoggingManagerInternal in project gradle by gradle.

the class AbstractMavenPublisher method execute.

private void execute(MavenPublishAction publishAction) {
    LoggingManagerInternal loggingManager = loggingManagerFactory.create();
    loggingManager.captureStandardOutput(LogLevel.INFO).start();
    try {
        publishAction.publish();
    } finally {
        loggingManager.stop();
    }
}
Also used : LoggingManagerInternal(org.gradle.internal.logging.LoggingManagerInternal)

Example 3 with LoggingManagerInternal

use of org.gradle.internal.logging.LoggingManagerInternal in project gradle by gradle.

the class SystemApplicationClassLoaderWorker method call.

public Void call() throws Exception {
    if (System.getProperty("org.gradle.worker.test.stuck") != null) {
        // Simulate a stuck worker. There's probably a way to inject this failure...
        Thread.sleep(30000);
        return null;
    }
    Decoder decoder = new InputStreamBackedDecoder(configInputStream);
    // Read logging config and setup logging
    int logLevel = decoder.readSmallInt();
    LoggingManagerInternal loggingManager = createLoggingManager();
    loggingManager.setLevelInternal(LogLevel.values()[logLevel]).start();
    // Read whether process info should be published
    boolean shouldPublishJvmMemoryInfo = decoder.readBoolean();
    // Read path to Gradle user home
    String gradleUserHomeDirPath = decoder.readString();
    File gradleUserHomeDir = new File(gradleUserHomeDirPath);
    // Read server address and start connecting
    MultiChoiceAddress serverAddress = new MultiChoiceAddressSerializer().read(decoder);
    MessagingServices messagingServices = new MessagingServices();
    final WorkerServices workerServices = new WorkerServices(messagingServices, gradleUserHomeDir);
    ObjectConnection connection = null;
    WorkerLogEventListener workerLogEventListener = null;
    try {
        // Read serialized worker
        byte[] serializedWorker = decoder.readBinary();
        // Deserialize the worker action
        Action<WorkerContext> action;
        try {
            ObjectInputStream instr = new ClassLoaderObjectInputStream(new ByteArrayInputStream(serializedWorker), getClass().getClassLoader());
            action = (Action<WorkerContext>) instr.readObject();
        } catch (Exception e) {
            throw UncheckedException.throwAsUncheckedException(e);
        }
        connection = messagingServices.get(MessagingClient.class).getConnection(serverAddress);
        workerLogEventListener = configureLogging(loggingManager, connection);
        if (shouldPublishJvmMemoryInfo) {
            configureWorkerJvmMemoryInfoEvents(workerServices, connection);
        }
        final ObjectConnection serverConnection = connection;
        action.execute(new WorkerContext() {

            public ClassLoader getApplicationClassLoader() {
                return ClassLoader.getSystemClassLoader();
            }

            @Override
            public ObjectConnection getServerConnection() {
                return serverConnection;
            }

            @Override
            public ServiceRegistry getServiceRegistry() {
                return workerServices;
            }
        });
    } finally {
        if (workerLogEventListener != null) {
            loggingManager.removeOutputEventListener(workerLogEventListener);
        }
        if (connection != null) {
            connection.stop();
        }
        messagingServices.close();
        loggingManager.stop();
    }
    return null;
}
Also used : InputStreamBackedDecoder(org.gradle.internal.serialize.InputStreamBackedDecoder) LoggingManagerInternal(org.gradle.internal.logging.LoggingManagerInternal) MessagingServices(org.gradle.internal.remote.services.MessagingServices) ClassLoaderObjectInputStream(org.gradle.internal.io.ClassLoaderObjectInputStream) Decoder(org.gradle.internal.serialize.Decoder) InputStreamBackedDecoder(org.gradle.internal.serialize.InputStreamBackedDecoder) ObjectConnection(org.gradle.internal.remote.ObjectConnection) UncheckedException(org.gradle.internal.UncheckedException) ByteArrayInputStream(java.io.ByteArrayInputStream) MultiChoiceAddress(org.gradle.internal.remote.internal.inet.MultiChoiceAddress) ServiceRegistry(org.gradle.internal.service.ServiceRegistry) DefaultServiceRegistry(org.gradle.internal.service.DefaultServiceRegistry) LoggingServiceRegistry(org.gradle.internal.logging.services.LoggingServiceRegistry) File(java.io.File) MultiChoiceAddressSerializer(org.gradle.internal.remote.internal.inet.MultiChoiceAddressSerializer) ObjectInputStream(java.io.ObjectInputStream) ClassLoaderObjectInputStream(org.gradle.internal.io.ClassLoaderObjectInputStream)

Example 4 with LoggingManagerInternal

use of org.gradle.internal.logging.LoggingManagerInternal in project gradle by gradle.

the class ProviderConnection method createExecuter.

private BuildActionExecuter<ProviderOperationParameters> createExecuter(ProviderOperationParameters operationParameters, Parameters params) {
    LoggingManagerInternal loggingManager;
    BuildActionExecuter<BuildActionParameters> executer;
    if (Boolean.TRUE.equals(operationParameters.isEmbedded())) {
        loggingManager = loggingServices.getFactory(LoggingManagerInternal.class).create();
        loggingManager.captureSystemSources();
        executer = embeddedExecutor;
    } else {
        LoggingServiceRegistry loggingServices = LoggingServiceRegistry.newNestedLogging();
        loggingManager = loggingServices.getFactory(LoggingManagerInternal.class).create();
        InputStream standardInput = operationParameters.getStandardInput();
        ServiceRegistry clientServices = daemonClientFactory.createBuildClientServices(loggingServices.get(OutputEventListener.class), params.daemonParams, standardInput == null ? SafeStreams.emptyInput() : standardInput);
        executer = clientServices.get(DaemonClient.class);
    }
    return new LoggingBridgingBuildActionExecuter(new DaemonBuildActionExecuter(executer, params.daemonParams), loggingManager);
}
Also used : LoggingManagerInternal(org.gradle.internal.logging.LoggingManagerInternal) DaemonClient(org.gradle.launcher.daemon.client.DaemonClient) InputStream(java.io.InputStream) BuildActionParameters(org.gradle.launcher.exec.BuildActionParameters) LoggingServiceRegistry(org.gradle.internal.logging.services.LoggingServiceRegistry) ServiceRegistry(org.gradle.internal.service.ServiceRegistry) OutputEventListener(org.gradle.internal.logging.events.OutputEventListener) LoggingServiceRegistry(org.gradle.internal.logging.services.LoggingServiceRegistry)

Example 5 with LoggingManagerInternal

use of org.gradle.internal.logging.LoggingManagerInternal in project gradle by gradle.

the class LoggingServiceRegistry method newCommandLineProcessLogging.

/**
 * Creates a set of logging services which are suitable to use globally in a process. In particular:
 *
 * <ul>
 * <li>Replaces System.out and System.err with implementations that route output through the logging system as per {@link LoggingManagerInternal#captureSystemSources()}.</li>
 * <li>Configures slf4j, log4j and java util logging to route log messages through the logging system.</li>
 * <li>Routes logging output to the original System.out and System.err as per {@link LoggingManagerInternal#attachSystemOutAndErr()}.</li>
 * <li>Sets log level to {@link org.gradle.api.logging.LogLevel#LIFECYCLE}.</li>
 * </ul>
 *
 * <p>Does nothing until started.</p>
 *
 * <p>Allows dynamic and colored output to be written to the console. Use {@link LoggingManagerInternal#attachProcessConsole(org.gradle.api.logging.configuration.ConsoleOutput)} to enable this.</p>
 */
public static LoggingServiceRegistry newCommandLineProcessLogging() {
    CommandLineLogging loggingServices = new CommandLineLogging();
    LoggingManagerInternal rootLoggingManager = loggingServices.get(DefaultLoggingManagerFactory.class).getRoot();
    rootLoggingManager.captureSystemSources();
    rootLoggingManager.attachSystemOutAndErr();
    return loggingServices;
}
Also used : LoggingManagerInternal(org.gradle.internal.logging.LoggingManagerInternal)

Aggregations

LoggingManagerInternal (org.gradle.internal.logging.LoggingManagerInternal)12 LoggingServiceRegistry (org.gradle.internal.logging.services.LoggingServiceRegistry)4 File (java.io.File)2 DefaultClassPath (org.gradle.internal.classpath.DefaultClassPath)2 ListenerManager (org.gradle.internal.event.ListenerManager)2 ServiceRegistry (org.gradle.internal.service.ServiceRegistry)2 Daemon (org.gradle.launcher.daemon.server.Daemon)2 DaemonServices (org.gradle.launcher.daemon.server.DaemonServices)2 DaemonExpirationStrategy (org.gradle.launcher.daemon.server.expiry.DaemonExpirationStrategy)2 Matchers.containsString (org.hamcrest.Matchers.containsString)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 EOFException (java.io.EOFException)1 InputStream (java.io.InputStream)1 ObjectInputStream (java.io.ObjectInputStream)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 TeeOutputStream (org.apache.commons.io.output.TeeOutputStream)1 BuildResult (org.gradle.BuildResult)1 UncheckedIOException (org.gradle.api.UncheckedIOException)1 ExceptionAnalyser (org.gradle.api.internal.ExceptionAnalyser)1