Spring Boot Log initialization with Spring Cloud Kubernetes

473 views Asked by At

Spring Boot 2.2.6-RELEASE

In my application.yml, I have this line :

logging.config: classpath:my-logback-config.xml

This works well, spring get its config nicely

In my my-logback-config.xml I have this line :

<springProperty name="LOG_HOST" source="config.logHost" />
<springProperty name="LOG_PORT" source="config.logPort" />

Again, this works well, it get its value from an external config file, which is defined in a ENV variable

SPRING_CONFIG_ADDITIONAL_LOCATION=file:/my-env.properties

But when I enable Spring Cloud Kubernetes, this fails, with an UnknowHostException : "LOG_HOST_IS_UNDEFINED" cannot be resolved. (the value of LOG_HOST is used to setup a network appender)

Why does enabling Spring Cloud Kubernetes change the behavior of logging initialization?

It seem that values from SPRING_CONFIG_ADDITIONAL_LOCATION are not loaded yet.

I can't load this value from a configMap, since Spring Cloud Kubernetes has not been initialized at the moment logging is being initialized.

1

There are 1 answers

0
Filip On

Finally, the problem was that the ENV var SPRING_CONFIG_ADDITIONAL_LOCATION was set to a folder, and not to a file on container.

Locally, on windows, setting 'SPRING_CONFIG_ADDITIONAL_LOCATION' to either a file or a folder seems to work, but in the Docker image (RH linux), it has an impact.

When SPRING_CONFIG_ADDITIONAL_LOCATION is set to a folder, values of the enclosed ".properties" files are ignored.

I can reproduce (fix) the issue by changing my docker file :

ENV SPRING_CONFIG_ADDITIONAL_LOCATION="/mnt/properties/application.properties"

to

ENV SPRING_CONFIG_ADDITIONAL_LOCATION="/mnt/properties/"