Unable To Use Springboot Properties In Destination XML Field
See original GitHub issueHi Team.
I have a working logstash encoder via TCP. I am able to use Springboot properties in the custom fields however when adding Springboot properties to the destination field it fails.
Here is my logback.xml:
<?xml version="1.0" encoding="UTF-8"?>
<configuration scan="true" scanPeriod="2 seconds">
<property name="LOGS" value="./" />
<property resource="application.yaml" />
<springProperty name="mvnVersion" source="info.app.version"/>
<springProperty name="appName" source="info.app.name"/>
<springProperty name="env" source="pulse.ingress.environment"/>
<springProperty name="logHost" source="pulse.logstash.host"/>
<appender name="stashTcp" class="net.logstash.logback.appender.LogstashTcpSocketAppender">
<destination>${logHost}</destination>
<encoder class="net.logstash.logback.encoder.LogstashEncoder">
<customFields>{"appName": "${appName}","env":"${env}","mvnVersion":"${mvnVersion}"}</customFields>
</encoder>
<writeBufferSize>0</writeBufferSize>
</appender>
Here is my relevant part of application.yaml:
pulse:
logstash:
host: 172.21.9.4:5044
When I try to use it like this I get the following exception on start up:
Exception in thread "main" java.lang.IllegalStateException: Logback configuration error detected:
ERROR in ch.qos.logback.core.joran.util.PropertySetter@9bd0fa6 - Could not invoke method addDestination in class net.logstash.logback.appender.LogstashTcpSocketAppender with parameter of type java.lang.String java.lang.reflect.InvocationTargetException
ERROR in net.logstash.logback.appender.LogstashTcpSocketAppender[stashTcp] - No destination was configured. Use <destination> to add one or more destinations to the appender
at org.springframework.boot.logging.logback.LogbackLoggingSystem.loadConfiguration(LogbackLoggingSystem.java:166)
at org.springframework.boot.logging.AbstractLoggingSystem.initializeWithConventions(AbstractLoggingSystem.java:79)
at org.springframework.boot.logging.AbstractLoggingSystem.initialize(AbstractLoggingSystem.java:59)
at org.springframework.boot.logging.logback.LogbackLoggingSystem.initialize(LogbackLoggingSystem.java:117)
at org.springframework.boot.context.logging.LoggingApplicationListener.initializeSystem(LoggingApplicationListener.java:279)
at org.springframework.boot.context.logging.LoggingApplicationListener.initialize(LoggingApplicationListener.java:254)
at org.springframework.boot.context.logging.LoggingApplicationListener.onApplicationEnvironmentPreparedEvent(LoggingApplicationListener.java:219)
at org.springframework.boot.context.logging.LoggingApplicationListener.onApplicationEvent(LoggingApplicationListener.java:196)
at org.springframework.context.event.SimpleApplicationEventMulticaster.doInvokeListener(SimpleApplicationEventMulticaster.java:172)
at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:165)
at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:139)
at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:127)
at org.springframework.boot.context.event.EventPublishingRunListener.environmentPrepared(EventPublishingRunListener.java:75)
at org.springframework.boot.SpringApplicationRunListeners.environmentPrepared(SpringApplicationRunListeners.java:53)
at org.springframework.boot.SpringApplication.prepareEnvironment(SpringApplication.java:340)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:304)
at org.springframework.boot.builder.SpringApplicationBuilder.run(SpringApplicationBuilder.java:139)
at org.springframework.cloud.bootstrap.BootstrapApplicationListener.bootstrapServiceContext(BootstrapApplicationListener.java:208)
at org.springframework.cloud.bootstrap.BootstrapApplicationListener.onApplicationEvent(BootstrapApplicationListener.java:104)
at org.springframework.cloud.bootstrap.BootstrapApplicationListener.onApplicationEvent(BootstrapApplicationListener.java:70)
at org.springframework.context.event.SimpleApplicationEventMulticaster.doInvokeListener(SimpleApplicationEventMulticaster.java:172)
at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:165)
at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:139)
at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:127)
at org.springframework.boot.context.event.EventPublishingRunListener.environmentPrepared(EventPublishingRunListener.java:75)
at org.springframework.boot.SpringApplicationRunListeners.environmentPrepared(SpringApplicationRunListeners.java:53)
at org.springframework.boot.SpringApplication.prepareEnvironment(SpringApplication.java:340)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:304)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1213)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1202)
at com.example.demo.PropertyTestApplication.main(PropertyTestApplication.java:13)
Note I have tried the following variations:
<destination>${logHost}</destination>
<destination>"${logHost}"</destination>
I am running two pipelines one for prod and the other for non-prod and I am hoping to inject the host name and port via K8S configmaps.
Thanks! Nam
Issue Analytics
- State:
- Created 4 years ago
- Comments:7
Top Results From Across the Web
Unable To Use Springboot Properties In Destination XML Field
I am able to use Springboot properties in the custom fields however when adding Springboot properties to the destination field it fails.
Read more >Unable to use Spring Property Placeholders in logback.xml
It appears as though the logback.xml is processed before Spring Boot fires up, therefore the EL placeholders are not processed. Using the FileNamePattern...
Read more >Common Application Properties - Spring
Name Description Default...
spring.cassandra.config Location of the configuration file to use.
spring.cassandra.controlconnection.timeout Timeout to use for control queries. 5s
spring.cassandra.keyspace‑name Keyspace name to use.
Read more >Configuring Logback with Spring Boot - CodinGame
In this tutorial we will focus on using XML to define custom logging configuration and look at some of the basics of doing...
Read more >Accessing application properties with Spring Boot properties API
The solution is located in the spring-boot-properties-quickstart directory. Creating the Maven project. First, we need a new project. Create a new project with ......
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I believe you need to name your configuration file
logback-spring.xml
in order to take advantage of thespringProperty
spring boot logback extensionAlso, you should remove the
<property resource="application.yaml" />
, since logback doesn’t support reading properties from yaml files directly. You’ll need to use thespringProperty
to access the spring properties.Also, remove the configuration scanning (which is not supported by the spring boot extensions)
After making those changes, it worked for me.
When I suppose spring-cloud-starter-oauth2 depends on, I also found the same problem and I don’t know how to deal with it. Also dependent on spring-security-oauth2-autoconfigure