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));
}
Aggregations