Search in sources :

Example 1 with LogConsole

use of com.google.copybara.util.console.LogConsole in project copybara by google.

the class Main method getConsole.

protected Console getConsole(String[] args) {
    boolean verbose = isVerbose(args);
    // If System.console() is not present, we are forced to use LogConsole
    Console console;
    if (System.console() == null) {
        console = LogConsole.writeOnlyConsole(System.err, verbose);
    } else if (Arrays.asList(args).contains(GeneralOptions.NOANSI)) {
        // The System.console doesn't detect redirects/pipes, but at least we have
        // jobs covered.
        console = LogConsole.readWriteConsole(System.in, System.err, verbose);
    } else {
        console = new AnsiConsole(System.in, System.err, verbose);
    }
    Optional<String> maybeConsoleFilePath = findFlagValue(args, GeneralOptions.CONSOLE_FILE_PATH);
    if (!maybeConsoleFilePath.isPresent()) {
        return console;
    }
    Path consoleFilePath = Paths.get(maybeConsoleFilePath.get());
    try {
        Files.createDirectories(consoleFilePath.getParent());
    } catch (IOException e) {
        logger.atSevere().withCause(e).log("Could not create parent directories to file: %s. Redirecting will be disabled.", consoleFilePath);
        return console;
    }
    return new FileConsole(console, consoleFilePath, getConsoleFlushRate(args));
}
Also used : Path(java.nio.file.Path) FileConsole(com.google.copybara.util.console.FileConsole) FileConsole(com.google.copybara.util.console.FileConsole) AnsiConsole(com.google.copybara.util.console.AnsiConsole) Console(com.google.copybara.util.console.Console) LogConsole(com.google.copybara.util.console.LogConsole) IOException(java.io.IOException) AnsiConsole(com.google.copybara.util.console.AnsiConsole)

Aggregations

AnsiConsole (com.google.copybara.util.console.AnsiConsole)1 Console (com.google.copybara.util.console.Console)1 FileConsole (com.google.copybara.util.console.FileConsole)1 LogConsole (com.google.copybara.util.console.LogConsole)1 IOException (java.io.IOException)1 Path (java.nio.file.Path)1