use of io.strimzi.operator.common.model.OrderedProperties in project strimzi by strimzi.
the class AbstractModel method parseLogging.
/**
* @param logging The Logging to parse.
* @param externalCm The external ConfigMap, used if Logging is an instance of ExternalLogging
* @return The logging properties as a String in log4j/2 properties file format.
*/
public String parseLogging(Logging logging, ConfigMap externalCm) {
if (logging instanceof InlineLogging) {
InlineLogging inlineLogging = (InlineLogging) logging;
OrderedProperties newSettings = getDefaultLogConfig();
if (inlineLogging.getLoggers() != null) {
// Inline logging as specified and some loggers are configured
if (shouldPatchLoggerAppender()) {
String rootAppenderName = getRootAppenderNamesFromDefaultLoggingConfig(newSettings);
String newRootLogger = inlineLogging.getLoggers().get("log4j.rootLogger");
newSettings.addMapPairs(inlineLogging.getLoggers());
if (newRootLogger != null && !rootAppenderName.isEmpty() && !newRootLogger.contains(",")) {
// this should never happen as appender name is added in default configuration
LOGGER.debugCr(reconciliation, "Newly set rootLogger does not contain appender. Setting appender to {}.", rootAppenderName);
String level = newSettings.asMap().get("log4j.rootLogger");
newSettings.addPair("log4j.rootLogger", level + ", " + rootAppenderName);
}
} else {
newSettings.addMapPairs(inlineLogging.getLoggers());
}
}
return createLog4jProperties(newSettings);
} else if (logging instanceof ExternalLogging) {
ExternalLogging externalLogging = (ExternalLogging) logging;
if (externalLogging.getValueFrom() != null && externalLogging.getValueFrom().getConfigMapKeyRef() != null && externalLogging.getValueFrom().getConfigMapKeyRef().getKey() != null) {
if (externalCm != null && externalCm.getData() != null && externalCm.getData().containsKey(externalLogging.getValueFrom().getConfigMapKeyRef().getKey())) {
return maybeAddMonitorIntervalToExternalLogging(externalCm.getData().get(externalLogging.getValueFrom().getConfigMapKeyRef().getKey()));
} else {
throw new InvalidResourceException(String.format("ConfigMap %s with external logging configuration does not exist or doesn't contain the configuration under the %s key.", externalLogging.getValueFrom().getConfigMapKeyRef().getName(), externalLogging.getValueFrom().getConfigMapKeyRef().getKey()));
}
} else {
throw new InvalidResourceException("Property logging.valueFrom has to be specified when using external logging.");
}
} else {
LOGGER.debugCr(reconciliation, "logging is not set, using default loggers");
return createLog4jProperties(getDefaultLogConfig());
}
}
Aggregations