Search in sources :

Example 36 with InlineLogging

use of io.strimzi.api.kafka.model.InlineLogging 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());
    }
}
Also used : ExternalLogging(io.strimzi.api.kafka.model.ExternalLogging) OrderedProperties(io.strimzi.operator.common.model.OrderedProperties) IntOrString(io.fabric8.kubernetes.api.model.IntOrString) InlineLogging(io.strimzi.api.kafka.model.InlineLogging)

Aggregations

InlineLogging (io.strimzi.api.kafka.model.InlineLogging)36 ParallelNamespaceTest (io.strimzi.systemtest.annotations.ParallelNamespaceTest)16 ExternalLogging (io.strimzi.api.kafka.model.ExternalLogging)14 ConfigMap (io.fabric8.kubernetes.api.model.ConfigMap)10 ConfigMapBuilder (io.fabric8.kubernetes.api.model.ConfigMapBuilder)10 ConfigMapKeySelectorBuilder (io.fabric8.kubernetes.api.model.ConfigMapKeySelectorBuilder)10 ExternalLoggingBuilder (io.strimzi.api.kafka.model.ExternalLoggingBuilder)10 Tag (org.junit.jupiter.api.Tag)10 IntOrString (io.fabric8.kubernetes.api.model.IntOrString)8 KafkaClusterSpec (io.strimzi.api.kafka.model.KafkaClusterSpec)8 Logging (io.strimzi.api.kafka.model.Logging)8 HashMap (java.util.HashMap)8 LabelSelector (io.fabric8.kubernetes.api.model.LabelSelector)6 Condition (io.strimzi.api.kafka.model.status.Condition)6 Storage (io.strimzi.api.kafka.model.storage.Storage)6 MetricsAndLogging (io.strimzi.operator.common.MetricsAndLogging)6 TestStorage (io.strimzi.systemtest.storage.TestStorage)6 Kafka (io.strimzi.api.kafka.model.Kafka)4 KafkaAuthorizationKeycloak (io.strimzi.api.kafka.model.KafkaAuthorizationKeycloak)4 KafkaConnect (io.strimzi.api.kafka.model.KafkaConnect)4