diff --git a/spring-cloud-kubernetes-config/src/main/java/org/springframework/cloud/kubernetes/config/ConfigMapPropertySource.java b/spring-cloud-kubernetes-config/src/main/java/org/springframework/cloud/kubernetes/config/ConfigMapPropertySource.java index d26cd499..0aa7a8a7 100644 --- a/spring-cloud-kubernetes-config/src/main/java/org/springframework/cloud/kubernetes/config/ConfigMapPropertySource.java +++ b/spring-cloud-kubernetes-config/src/main/java/org/springframework/cloud/kubernetes/config/ConfigMapPropertySource.java @@ -27,14 +27,15 @@ import java.util.stream.Collectors; import io.fabric8.kubernetes.api.model.ConfigMap; import io.fabric8.kubernetes.client.KubernetesClient; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import org.springframework.beans.factory.config.YamlPropertiesFactoryBean; import org.springframework.core.env.MapPropertySource; import org.springframework.core.io.ByteArrayResource; public class ConfigMapPropertySource extends MapPropertySource { - private static final Logger LOGGER = LoggerFactory.getLogger(ConfigMapPropertySource.class); + private static final Log LOG = LogFactory.getLog(ConfigMapPropertySource.class); private static final String APPLICATION_YML = "application.yml"; private static final String APPLICATION_YAML = "application.yaml"; @@ -81,7 +82,7 @@ public class ConfigMapPropertySource extends MapPropertySource { } } } catch (Exception e) { - LOGGER.warn("Can't read configMap with name: [" + name + "] in namespace:[" + namespace + "]. Ignoring"); + LOG.warn("Can't read configMap with name: [" + name + "] in namespace:[" + namespace + "]. Ignoring"); } return result; } diff --git a/spring-cloud-kubernetes-config/src/main/java/org/springframework/cloud/kubernetes/config/ConfigUtils.java b/spring-cloud-kubernetes-config/src/main/java/org/springframework/cloud/kubernetes/config/ConfigUtils.java index 96981e4f..c055e3af 100644 --- a/spring-cloud-kubernetes-config/src/main/java/org/springframework/cloud/kubernetes/config/ConfigUtils.java +++ b/spring-cloud-kubernetes-config/src/main/java/org/springframework/cloud/kubernetes/config/ConfigUtils.java @@ -1,7 +1,7 @@ package org.springframework.cloud.kubernetes.config; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import org.springframework.core.env.Environment; import org.springframework.util.StringUtils; @@ -12,14 +12,17 @@ import static org.springframework.cloud.kubernetes.config.Constants.SPRING_APPLI public class ConfigUtils { - private static final Logger LOGGER = LoggerFactory.getLogger(SecretsPropertySource.class); + private static final Log LOG = LogFactory.getLog(SecretsPropertySource.class); public static String getApplicationName(Environment env, C config) { String name = config.getName(); if (StringUtils.isEmpty(name)) { //TODO: use relaxed binding - LOGGER.debug(config.getConfigurationTarget() + " name has not been set, taking it from property/env {} (default={})", - SPRING_APPLICATION_NAME, FALLBACK_APPLICATION_NAME); + if (LOG.isDebugEnabled()) { + LOG.debug(config.getConfigurationTarget() + + " name has not been set, taking it from property/env " + + SPRING_APPLICATION_NAME + " (default=" + FALLBACK_APPLICATION_NAME + ")"); + } name = env.getProperty(SPRING_APPLICATION_NAME, FALLBACK_APPLICATION_NAME); } @@ -30,8 +33,9 @@ public class ConfigUtils { public static String getApplicationNamespace(KubernetesClient client, Environment env, C config) { String namespace = config.getNamespace(); if (StringUtils.isEmpty(namespace)) { - LOGGER.debug(config.getConfigurationTarget() + " namespace has not been set, taking it from client (ns={})", - client.getNamespace()); + if (LOG.isDebugEnabled()) { + LOG.debug(config.getConfigurationTarget() + " namespace has not been set, taking it from client (ns="+client.getNamespace()+")"); + } namespace = client.getNamespace(); } diff --git a/spring-cloud-kubernetes-config/src/main/java/org/springframework/cloud/kubernetes/config/SecretsPropertySource.java b/spring-cloud-kubernetes-config/src/main/java/org/springframework/cloud/kubernetes/config/SecretsPropertySource.java index 508ffea1..39d68cd9 100644 --- a/spring-cloud-kubernetes-config/src/main/java/org/springframework/cloud/kubernetes/config/SecretsPropertySource.java +++ b/spring-cloud-kubernetes-config/src/main/java/org/springframework/cloud/kubernetes/config/SecretsPropertySource.java @@ -26,8 +26,9 @@ import java.util.Map; import io.fabric8.kubernetes.api.model.Secret; import io.fabric8.kubernetes.client.KubernetesClient; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import org.springframework.core.env.Environment; import org.springframework.core.env.MapPropertySource; import org.springframework.util.StringUtils; @@ -35,7 +36,7 @@ import org.springframework.util.StringUtils; import static org.springframework.cloud.kubernetes.config.ConfigUtils.*; public class SecretsPropertySource extends MapPropertySource { - private static final Logger LOGGER = LoggerFactory.getLogger(SecretsPropertySource.class); + private static final Log LOG = LogFactory.getLog(SecretsPropertySource.class); private static final String PREFIX = "secrets"; @@ -97,11 +98,10 @@ public class SecretsPropertySource extends MapPropertySource { } } } catch (Exception e) { - LOGGER.warn("Can't read secret with name: [{}] or labels [{}] in namespace:[{}] (cause: {}). Ignoring", - name, - config.getLabels(), - namespace, - e.getMessage()); + LOG.warn("Can't read secret with name: [" + name + + "] or labels [" + config.getLabels() + + "] in namespace:[" + namespace + + "] (cause: " + e.getMessage() + "). Ignoring"); } } @@ -133,7 +133,7 @@ public class SecretsPropertySource extends MapPropertySource { .filter(Files::isRegularFile) .forEach(p -> readFile(p, result)); } catch (IOException e) { - LOGGER.warn("", e); + LOG.warn("", e); } } @@ -143,7 +143,7 @@ public class SecretsPropertySource extends MapPropertySource { path.getFileName().toString(), new String(Files.readAllBytes(path)).trim()); } catch (IOException e) { - LOGGER.warn("", e); + LOG.warn("", e); } } } diff --git a/spring-cloud-kubernetes-config/src/main/java/org/springframework/cloud/kubernetes/config/reload/ConfigurationChangeDetector.java b/spring-cloud-kubernetes-config/src/main/java/org/springframework/cloud/kubernetes/config/reload/ConfigurationChangeDetector.java index 74058a3d..1f05678c 100644 --- a/spring-cloud-kubernetes-config/src/main/java/org/springframework/cloud/kubernetes/config/reload/ConfigurationChangeDetector.java +++ b/spring-cloud-kubernetes-config/src/main/java/org/springframework/cloud/kubernetes/config/reload/ConfigurationChangeDetector.java @@ -23,8 +23,8 @@ import javax.annotation.PreDestroy; import io.fabric8.kubernetes.client.KubernetesClient; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import org.springframework.core.env.CompositePropertySource; import org.springframework.core.env.ConfigurableEnvironment; import org.springframework.core.env.MapPropertySource; @@ -35,7 +35,7 @@ import org.springframework.core.env.PropertySource; */ public abstract class ConfigurationChangeDetector { - protected Logger log = LoggerFactory.getLogger(getClass()); + protected Log log = LogFactory.getLog(getClass()); protected ConfigurableEnvironment environment; diff --git a/spring-cloud-kubernetes-config/src/main/java/org/springframework/cloud/kubernetes/config/reload/EventBasedConfigurationChangeDetector.java b/spring-cloud-kubernetes-config/src/main/java/org/springframework/cloud/kubernetes/config/reload/EventBasedConfigurationChangeDetector.java index 33908ce0..4f0dc34e 100644 --- a/spring-cloud-kubernetes-config/src/main/java/org/springframework/cloud/kubernetes/config/reload/EventBasedConfigurationChangeDetector.java +++ b/spring-cloud-kubernetes-config/src/main/java/org/springframework/cloud/kubernetes/config/reload/EventBasedConfigurationChangeDetector.java @@ -78,7 +78,7 @@ public class EventBasedConfigurationChangeDetector extends ConfigurationChangeDe } })); activated = true; - log.info("Added new Kubernetes watch: {}", name); + log.info("Added new Kubernetes watch: "+name); } catch (Exception e) { log.error("Error while establishing a connection to watch config maps: configuration may remain stale", e); } @@ -100,7 +100,7 @@ public class EventBasedConfigurationChangeDetector extends ConfigurationChangeDe } })); activated = true; - log.info("Added new Kubernetes watch: {}", name); + log.info("Added new Kubernetes watch: " + name); } catch (Exception e) { log.error("Error while establishing a connection to watch secrets: configuration may remain stale", e); } @@ -116,7 +116,7 @@ public class EventBasedConfigurationChangeDetector extends ConfigurationChangeDe if (this.watches != null) { for (Map.Entry entry : this.watches.entrySet()) { try { - log.debug("Closing the watch {}", entry.getKey()); + log.debug("Closing the watch "+ entry.getKey()); entry.getValue().close(); } catch (Exception e) { diff --git a/spring-cloud-kubernetes-core/src/main/java/org/springframework/cloud/kubernetes/StandardPodUtils.java b/spring-cloud-kubernetes-core/src/main/java/org/springframework/cloud/kubernetes/StandardPodUtils.java index e58b5248..87d6f551 100644 --- a/spring-cloud-kubernetes-core/src/main/java/org/springframework/cloud/kubernetes/StandardPodUtils.java +++ b/spring-cloud-kubernetes-core/src/main/java/org/springframework/cloud/kubernetes/StandardPodUtils.java @@ -19,15 +19,16 @@ package org.springframework.cloud.kubernetes; import io.fabric8.kubernetes.api.model.Pod; import io.fabric8.kubernetes.client.Config; import io.fabric8.kubernetes.client.KubernetesClient; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import java.nio.file.Paths; import java.util.function.Supplier; public class StandardPodUtils implements PodUtils { - private static final Logger LOGGER = LoggerFactory.getLogger(StandardPodUtils.class); + private static final Log LOG = LogFactory.getLog(StandardPodUtils.class); public static final String HOSTNAME = "HOSTNAME"; private final KubernetesClient client; @@ -58,7 +59,7 @@ public class StandardPodUtils implements PodUtils { return null; } } catch (Throwable t) { - LOGGER.warn("Failed to get pod with name:[" + hostName + "]. You should look into this if things aren't working as you expect. Are you missing serviceaccount permissions?", t); + LOG.warn("Failed to get pod with name:[" + hostName + "]. You should look into this if things aren't working as you expect. Are you missing serviceaccount permissions?", t); return null; } } diff --git a/spring-cloud-kubernetes-core/src/main/java/org/springframework/cloud/kubernetes/profile/KubernetesProfileApplicationListener.java b/spring-cloud-kubernetes-core/src/main/java/org/springframework/cloud/kubernetes/profile/KubernetesProfileApplicationListener.java index 0299cb49..6c28edbc 100644 --- a/spring-cloud-kubernetes-core/src/main/java/org/springframework/cloud/kubernetes/profile/KubernetesProfileApplicationListener.java +++ b/spring-cloud-kubernetes-core/src/main/java/org/springframework/cloud/kubernetes/profile/KubernetesProfileApplicationListener.java @@ -17,9 +17,10 @@ package org.springframework.cloud.kubernetes.profile; import io.fabric8.kubernetes.api.model.Pod; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import org.springframework.cloud.kubernetes.PodUtils; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import org.springframework.boot.context.event.ApplicationEnvironmentPreparedEvent; import org.springframework.context.ApplicationListener; import org.springframework.core.Ordered; @@ -28,7 +29,7 @@ import org.springframework.core.env.Environment; public class KubernetesProfileApplicationListener implements ApplicationListener, Ordered { - private static final Logger LOGGER = LoggerFactory.getLogger(KubernetesProfileApplicationListener.class); + private static final Log LOG = LogFactory.getLog(KubernetesProfileApplicationListener.class); private static final String KUBERNETES_PROFILE = "kubernetes"; private static final int OFFSET = 1; @@ -55,14 +56,18 @@ public class KubernetesProfileApplicationListener implements ApplicationListener if (utils.isInsideKubernetes()) { if (hasKubernetesProfile(environment)) { - LOGGER.debug("'kubernetes' already in list of active profiles"); + if (LOG.isDebugEnabled()) { + LOG.debug("'kubernetes' already in list of active profiles"); + } } else { - LOGGER.debug("Adding 'kubernetes' to list of active profiles"); + if (LOG.isDebugEnabled()) { + LOG.debug("Adding 'kubernetes' to list of active profiles"); + } environment.addActiveProfile(KUBERNETES_PROFILE); } } else { - if (LOGGER.isDebugEnabled()) { - LOGGER.warn("Not running inside kubernetes. Skipping 'kuberntes' profile activation."); + if (LOG.isDebugEnabled()) { + LOG.warn("Not running inside kubernetes. Skipping 'kuberntes' profile activation."); } } } diff --git a/spring-cloud-kubernetes-ribbon/pom.xml b/spring-cloud-kubernetes-ribbon/pom.xml index 6bcd9b11..c930af98 100644 --- a/spring-cloud-kubernetes-ribbon/pom.xml +++ b/spring-cloud-kubernetes-ribbon/pom.xml @@ -62,6 +62,12 @@ true + + org.springframework.boot + spring-boot-starter-logging + true + + com.netflix.archaius archaius-core diff --git a/spring-cloud-kubernetes-ribbon/src/main/java/org/springframework/cloud/kubernetes/ribbon/KubernetesServerList.java b/spring-cloud-kubernetes-ribbon/src/main/java/org/springframework/cloud/kubernetes/ribbon/KubernetesServerList.java index ff812ec3..9c494915 100644 --- a/spring-cloud-kubernetes-ribbon/src/main/java/org/springframework/cloud/kubernetes/ribbon/KubernetesServerList.java +++ b/spring-cloud-kubernetes-ribbon/src/main/java/org/springframework/cloud/kubernetes/ribbon/KubernetesServerList.java @@ -21,24 +21,26 @@ import com.netflix.client.config.IClientConfig; import com.netflix.loadbalancer.AbstractServerList; import com.netflix.loadbalancer.Server; import com.netflix.loadbalancer.ServerList; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + import io.fabric8.kubernetes.api.model.EndpointAddress; import io.fabric8.kubernetes.api.model.EndpointPort; import io.fabric8.kubernetes.api.model.EndpointSubset; import io.fabric8.kubernetes.api.model.Endpoints; import io.fabric8.kubernetes.client.KubernetesClient; import io.fabric8.kubernetes.client.utils.Utils; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; + import java.util.ArrayList; import java.util.Collections; import java.util.List; -import java.util.stream.Collectors; public class KubernetesServerList extends AbstractServerList implements ServerList { private static final int FIRST = 0; - private static final Logger LOG = LoggerFactory.getLogger(KubernetesServerList.class); + private static final Log LOG = LogFactory.getLog(KubernetesServerList.class); private final KubernetesClient client; diff --git a/spring-cloud-kubernetes-zipkin/src/main/java/org/springframework/cloud/kubernetes/zipkin/ZipkinKubernetesAutoConfiguration.java b/spring-cloud-kubernetes-zipkin/src/main/java/org/springframework/cloud/kubernetes/zipkin/ZipkinKubernetesAutoConfiguration.java index ee5df910..90126c1c 100644 --- a/spring-cloud-kubernetes-zipkin/src/main/java/org/springframework/cloud/kubernetes/zipkin/ZipkinKubernetesAutoConfiguration.java +++ b/spring-cloud-kubernetes-zipkin/src/main/java/org/springframework/cloud/kubernetes/zipkin/ZipkinKubernetesAutoConfiguration.java @@ -21,8 +21,6 @@ import io.fabric8.kubernetes.api.model.Endpoints; import io.fabric8.kubernetes.client.KubernetesClient; import io.fabric8.kubernetes.client.utils.Utils; import org.springframework.cloud.kubernetes.discovery.KubernetesServiceInstance; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import org.springframework.boot.autoconfigure.AutoConfigureBefore; import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.boot.context.properties.EnableConfigurationProperties; @@ -47,7 +45,6 @@ import java.util.stream.Collectors; @AutoConfigureBefore(ZipkinAutoConfiguration.class) public class ZipkinKubernetesAutoConfiguration { - private static final Logger LOGGER = LoggerFactory.getLogger(ZipkinKubernetesAutoConfiguration.class); @Bean public ZipkinSpanReporter reporter(KubernetesClient client, KubernetesZipkinDiscoveryProperties discoveryProperties, SpanMetricReporter spanMetricReporter, ZipkinProperties zipkin) {