use of com.teamscale.jacoco.agent.options.FilePatternResolver in project teamscale-jacoco-agent by cqse.
the class AgentBase method initializeFallbackLogging.
/**
* Initializes fallback logging in case of an error during the parsing of the options to {@link #premain(String,
* Instrumentation)} (see TS-23151). This tries to extract the logging configuration and use this and falls back to
* the default logger.
*/
private static LoggingResources initializeFallbackLogging(String premainOptions, DelayedLogger delayedLogger) {
for (String optionPart : premainOptions.split(",")) {
if (optionPart.startsWith(AgentOptionsParser.LOGGING_CONFIG_OPTION + "=")) {
return createFallbackLoggerFromConfig(optionPart.split("=", 2)[1], delayedLogger);
}
if (optionPart.startsWith(AgentOptionsParser.CONFIG_FILE_OPTION + "=")) {
String configFileValue = optionPart.split("=", 2)[1];
Optional<String> loggingConfigLine = Optional.empty();
try {
File configFile = new FilePatternResolver(delayedLogger).parsePath(AgentOptionsParser.CONFIG_FILE_OPTION, configFileValue).toFile();
loggingConfigLine = FileSystemUtils.readLinesUTF8(configFile).stream().filter(line -> line.startsWith(AgentOptionsParser.LOGGING_CONFIG_OPTION + "=")).findFirst();
} catch (IOException | AgentOptionParseException e) {
delayedLogger.error("Failed to load configuration from " + configFileValue + ": " + e.getMessage(), e);
}
if (loggingConfigLine.isPresent()) {
return createFallbackLoggerFromConfig(loggingConfigLine.get().split("=", 2)[1], delayedLogger);
}
}
}
return LoggingUtils.initializeDefaultLogging();
}
Aggregations