Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade to 7.3 causes: Could not invoke method setProviders #936

Closed
hjannasch opened this issue Feb 21, 2023 · 2 comments
Closed

Upgrade to 7.3 causes: Could not invoke method setProviders #936

hjannasch opened this issue Feb 21, 2023 · 2 comments

Comments

@hjannasch
Copy link

hjannasch commented Feb 21, 2023

Spring Boot Version 2.7.8
Logback version 1.2.11
Java Version latest 17 LTS

After upgrading to 7.3 the following exception is throws during Spring Boot startup:

ERROR in ch.qos.logback.core.joran.spi.Interpreter@9:17 - no applicable action for [mdc], current ElementPath  is [[configuration][appender][encoder][providers][mdc]]
ERROR in ch.qos.logback.core.joran.util.PropertySetter@50adedaa - Could not invoke method setProviders in class net.logstash.logback.encoder.LogstashEncoder with parameter of type net.logstash.logback.composite.JsonProviders java.lang.reflect.InvocationTargetException
		at org.springframework.boot.context.logging.LoggingApplicationListener.initializeSystem(LoggingApplicationListener.java:344)
		at org.springframework.boot.context.logging.LoggingApplicationListener.initialize(LoggingApplicationListener.java:298)
		at org.springframework.boot.context.logging.LoggingApplicationListener.onApplicationEnvironmentPreparedEvent(LoggingApplicationListener.java:246)
		at org.springframework.boot.context.logging.LoggingApplicationListener.onApplicationEvent(LoggingApplicationListener.java:223)
		at org.springframework.context.event.SimpleApplicationEventMulticaster.doInvokeListener(SimpleApplicationEventMulticaster.java:176)
		at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:169)
		at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:143)
		at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:131)
		at org.springframework.boot.context.event.EventPublishingRunListener.environmentPrepared(EventPublishingRunListener.java:85)
		at org.springframework.boot.SpringApplicationRunListeners.lambda$environmentPrepared$2(SpringApplicationRunListeners.java:66)
		at java.base/java.util.ArrayList.forEach(ArrayList.java:1511)
		at org.springframework.boot.SpringApplicationRunListeners.doWithListeners(SpringApplicationRunListeners.java:120)
		at org.springframework.boot.SpringApplicationRunListeners.doWithListeners(SpringApplicationRunListeners.java:114)
		at org.springframework.boot.SpringApplicationRunListeners.environmentPrepared(SpringApplicationRunListeners.java:65)
		at org.springframework.boot.SpringApplication.prepareEnvironment(SpringApplication.java:343)
		at org.springframework.boot.SpringApplication.run(SpringApplication.java:301)
		at org.springframework.boot.test.context.SpringBootContextLoader.loadContext(SpringBootContextLoader.java:136)
		at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContextInternal(DefaultCacheAwareContextLoaderDelegate.java:141)
		at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:90)
		... 83 more
	Caused by: java.lang.IllegalStateException: Logback configuration error detected: 

My logback-spring.xml look like:

xml<?xml version="1.0" encoding="UTF-8"?>
<configuration>
  <springProfile name="!local">
    <!-- Use JSON format for processing with Filebeat -->
    <appender name="jsonConsoleAppender" class="ch.qos.logback.core.ConsoleAppender">
      <encoder class="net.logstash.logback.encoder.LogstashEncoder">
        <providers>
          <mdc/>
        </providers>
      </encoder>
    </appender>
    <root level="INFO">
      <appender-ref ref="jsonConsoleAppender"/>
    </root>
  </springProfile>

  <springProfile name="local">
    <include resource="org/springframework/boot/logging/logback/base.xml"/>
  </springProfile>
</configuration>

When removing the mdc provider tag the error is gone. Is this tag deprecated?

@philsttr
Copy link
Collaborator

philsttr commented Feb 21, 2023

Hi @hjannasch

net.logstash.logback.encoder.LogstashEncoder does not allow setting providers using the <providers> element. (Only net.logstash.logback.encoder.LoggingEventCompositeJsonEncoder allows using the <providers> element)

Prior to 7.3, logstash-logback-encoder would ignore the invalid configuration and continue.

In 7.3, logstash-logback-encoder will throw an exception for the invalid configuration. (#861)

You likely did not notice this previously, because the mdc provider is included by default in net.logstash.logback.encoder.LogstashEncoder. Therefore, there is no need to explicitly include it.

If you would like to add additional providers to a net.logstash.logback.encoder.LogstashEncoder (which are not included by default), then you can use the <provider class="..."> element

@hjannasch
Copy link
Author

Thanks for your feedback. I will remove the mdc provider from the config file.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants