in daemon-m39/src/main/java/org/apache/maven/cli/DaemonMavenCli.java [366:426]
void logging(CliRequest cliRequest) {
// LOG LEVEL
cliRequest.debug = cliRequest.commandLine.hasOption(CLIManager.DEBUG);
cliRequest.quiet = !cliRequest.debug && cliRequest.commandLine.hasOption(CLIManager.QUIET);
cliRequest.showErrors = cliRequest.debug || cliRequest.commandLine.hasOption(CLIManager.ERRORS);
Slf4jConfiguration slf4jConfiguration = Slf4jConfigurationFactory.getConfiguration(slf4jLoggerFactory);
if (cliRequest.debug) {
cliRequest.request.setLoggingLevel(MavenExecutionRequest.LOGGING_LEVEL_DEBUG);
slf4jConfiguration.setRootLoggerLevel(Slf4jConfiguration.Level.DEBUG);
} else if (cliRequest.quiet) {
cliRequest.request.setLoggingLevel(MavenExecutionRequest.LOGGING_LEVEL_ERROR);
slf4jConfiguration.setRootLoggerLevel(Slf4jConfiguration.Level.ERROR);
}
// else fall back to default log level specified in conf
// see https://issues.apache.org/jira/browse/MNG-2570
// LOG COLOR
String styleColor = cliRequest.getUserProperties().getProperty(STYLE_COLOR_PROPERTY, "auto");
if ("always".equals(styleColor)) {
MessageUtils.setColorEnabled(true);
} else if ("never".equals(styleColor)) {
MessageUtils.setColorEnabled(false);
} else if (!"auto".equals(styleColor)) {
throw new IllegalArgumentException("Invalid color configuration option [" + styleColor
+ "]. Supported values are (auto|always|never).");
} else if (cliRequest.commandLine.hasOption(CLIManager.BATCH_MODE)
|| cliRequest.commandLine.hasOption(CLIManager.LOG_FILE)) {
MessageUtils.setColorEnabled(false);
}
// LOG STREAMS
if (cliRequest.commandLine.hasOption(CLIManager.LOG_FILE)) {
File logFile = new File(cliRequest.commandLine.getOptionValue(CLIManager.LOG_FILE));
logFile = resolveFile(logFile, cliRequest.workingDirectory);
// redirect stdout and stderr to file
try {
PrintStream ps = new PrintStream(new FileOutputStream(logFile), true);
System.setOut(ps);
System.setErr(ps);
} catch (FileNotFoundException e) {
//
// Ignore
//
}
} else if (!Environment.MVND_RAW_STREAMS
.asOptional()
.map(Boolean::parseBoolean)
.orElse(Boolean.FALSE)) {
MvndSimpleLogger stdout = (MvndSimpleLogger) slf4jLoggerFactory.getLogger("stdout");
MvndSimpleLogger stderr = (MvndSimpleLogger) slf4jLoggerFactory.getLogger("stderr");
stdout.setLogLevel(LocationAwareLogger.INFO_INT);
stderr.setLogLevel(LocationAwareLogger.INFO_INT);
System.setOut(new LoggingOutputStream(s -> stdout.info("[stdout] " + s)).printStream());
System.setErr(new LoggingOutputStream(s -> stderr.warn("[stderr] " + s)).printStream());
}
slf4jConfiguration.activate();
}