Not able to load logback.xml from Consul

2019-08-26 20:48发布

The issue goes like this

I have all my configuration for the project in Consul KV store The configuration includes application.yml, logback.xml and few other configurations needed by my project.

Using bootstrap.yml for Spring Cloud Consul configuration which contains logging.config for with the URI of the configuration URI is as follow for logging.config - http://CONSUL_SERVER_IP:CONSUL_SERVER_PORT/v1/kv/CONSUL_CONFIG_PREFIX/logback.xml?raw

Also tried passing below as argument/VM argument

-Dlogging.config=http://CONSUL_SERVER_IP:CONSUL_SERVER_PORT/v1/kv/CONSUL_CONFIG_PREFIX/logback.xml?raw

Query string 'raw' is needed to get the actual config file.

While executing the application it gives the following error

Caused by: ch.qos.logback.core.LogbackException: Unexpected filename extension of file [http://CONSUL_SERVER_IP:CONSUL_SERVER_PORT/v1/kv/CONSUL_CONFIG_PREFIX/logback.xml?raw]. Should be either .groovy or .xml at ch.qos.logback.classic.util.ContextInitializer.configureByResource(ContextInitializer.java:77) at org.springframework.boot.logging.logback.LogbackLoggingSystem.configureByResourceUrl(LogbackLoggingSystem.java:180) at org.springframework.boot.logging.logback.LogbackLoggingSystem.loadConfiguration(LogbackLoggingSystem.java:149) ... 30 more

Spring boot version - 2.0.1.RELEASE

Spring cloud version - Finchley.SR2

logback classic and core version - 1.2.3

1条回答
Explosion°爆炸
2楼-- · 2019-08-26 21:04

Following solution, worked for me. Just change the URI passed to logging.config in bootstrap.yml or as VM arguments

http://CONSUL_SERVER_IP:CONSUL_SERVER_PORT/v1/kv/CONSUL_CONFIG_PREFIX/logback.xml?raw=true&xml

If you have a similar issue then add &fileExtension to the URI

查看更多
登录 后发表回答