Search in sources :

Example 1 with ConsoleOutput

use of org.gradle.api.logging.configuration.ConsoleOutput in project gradle by gradle.

the class InProcessGradleExecuter method createLoggingManager.

private LoggingManagerInternal createLoggingManager(StartParameter startParameter, OutputStream outputStream, OutputStream errorStream) {
    LoggingManagerInternal loggingManager = GLOBAL_SERVICES.getFactory(LoggingManagerInternal.class).create();
    loggingManager.captureSystemSources();
    ConsoleOutput consoleOutput = startParameter.getConsoleOutput();
    loggingManager.attachConsole(new TeeOutputStream(System.out, outputStream), new TeeOutputStream(System.err, errorStream), consoleOutput, consoleAttachment.getConsoleMetaData());
    return loggingManager;
}
Also used : LoggingManagerInternal(org.gradle.internal.logging.LoggingManagerInternal) ConsoleOutput(org.gradle.api.logging.configuration.ConsoleOutput) TeeOutputStream(org.apache.commons.io.output.TeeOutputStream)

Example 2 with ConsoleOutput

use of org.gradle.api.logging.configuration.ConsoleOutput in project gradle by gradle.

the class LoggingCommandLineConverter method convert.

public LoggingConfiguration convert(ParsedCommandLine commandLine, LoggingConfiguration loggingConfiguration) throws CommandLineArgumentException {
    for (Map.Entry<String, LogLevel> entry : logLevelMap.entrySet()) {
        if (commandLine.hasOption(entry.getKey())) {
            loggingConfiguration.setLogLevel(entry.getValue());
        }
    }
    for (Map.Entry<String, ShowStacktrace> entry : showStacktraceMap.entrySet()) {
        if (commandLine.hasOption(entry.getKey())) {
            loggingConfiguration.setShowStacktrace(entry.getValue());
        }
    }
    if (commandLine.hasOption(CONSOLE)) {
        String value = commandLine.option(CONSOLE).getValue();
        String consoleValue = StringUtils.capitalize(value.toLowerCase(Locale.ENGLISH));
        try {
            ConsoleOutput consoleOutput = ConsoleOutput.valueOf(consoleValue);
            loggingConfiguration.setConsoleOutput(consoleOutput);
        } catch (IllegalArgumentException e) {
            throw new CommandLineArgumentException(String.format("Unrecognized value '%s' for %s.", value, CONSOLE));
        }
    }
    return loggingConfiguration;
}
Also used : ConsoleOutput(org.gradle.api.logging.configuration.ConsoleOutput) CommandLineArgumentException(org.gradle.cli.CommandLineArgumentException) BiMap(com.google.common.collect.BiMap) HashBiMap(com.google.common.collect.HashBiMap) Map(java.util.Map) LogLevel(org.gradle.api.logging.LogLevel) ShowStacktrace(org.gradle.api.logging.configuration.ShowStacktrace)

Example 3 with ConsoleOutput

use of org.gradle.api.logging.configuration.ConsoleOutput in project gradle by gradle.

the class InProcessGradleExecuter method createLoggingManager.

private LoggingManagerInternal createLoggingManager(StartParameter startParameter, final StandardOutputListener outputListener) {
    LoggingManagerInternal loggingManager = GLOBAL_SERVICES.getFactory(LoggingManagerInternal.class).create();
    loggingManager.captureSystemSources();
    ConsoleOutput consoleOutput = startParameter.getConsoleOutput();
    if (consoleOutput == ConsoleOutput.Auto) {
        // IDEA runs tests attached to a console, use plain so test can assume never attached to a console
        // Should really run all tests against a plain and a rich console to make these assumptions explicit
        consoleOutput = ConsoleOutput.Plain;
    }
    loggingManager.attachConsole(new TeeOutputStream(System.out, new LineBufferingOutputStream(new TextStream() {

        @Override
        public void text(String text) {
            outputListener.onOutput(text);
        }

        @Override
        public void endOfStream(@Nullable Throwable failure) {
        }
    })), consoleOutput);
    return loggingManager;
}
Also used : LoggingManagerInternal(org.gradle.internal.logging.LoggingManagerInternal) ConsoleOutput(org.gradle.api.logging.configuration.ConsoleOutput) TeeOutputStream(org.apache.commons.io.output.TeeOutputStream) LineBufferingOutputStream(org.gradle.internal.io.LineBufferingOutputStream) Matchers.containsString(org.hamcrest.Matchers.containsString) TextStream(org.gradle.internal.io.TextStream)

Aggregations

ConsoleOutput (org.gradle.api.logging.configuration.ConsoleOutput)3 TeeOutputStream (org.apache.commons.io.output.TeeOutputStream)2 LoggingManagerInternal (org.gradle.internal.logging.LoggingManagerInternal)2 BiMap (com.google.common.collect.BiMap)1 HashBiMap (com.google.common.collect.HashBiMap)1 Map (java.util.Map)1 LogLevel (org.gradle.api.logging.LogLevel)1 ShowStacktrace (org.gradle.api.logging.configuration.ShowStacktrace)1 CommandLineArgumentException (org.gradle.cli.CommandLineArgumentException)1 LineBufferingOutputStream (org.gradle.internal.io.LineBufferingOutputStream)1 TextStream (org.gradle.internal.io.TextStream)1 Matchers.containsString (org.hamcrest.Matchers.containsString)1