question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Spring Boot 2.2.2.RELEASE with logstash-logback-encoder Versions > 5.2 service fails with System.Exit 0

See original GitHub issue

Hi, we have tried to use Spring Boot 2.2.2.RELEASE with logstash-logback-encoder:

<dependency>
            <groupId>net.logstash.logback</groupId>
            <artifactId>logstash-logback-encoder</artifactId>
            <version>6.3</version>
        </dependency>

together with JSON formatted structured logging.

application.properties is working otherwise with non-json logging.

logback-spring.xml looks something like this:

<springProfile name="local">
        <property resource="application.properties" />
        <contextName>${spring.application.name}</contextName>
        <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
            <encoder class="net.logstash.logback.encoder.LoggingEventCompositeJsonEncoder">
                <providers>
                    <contextName>
                        <fieldName>appName</fieldName>
                    </contextName>
                    <threadName>
                        <fieldName>appThread</fieldName>
                    </threadName>
                    <timestamp>
                        <fieldName>appTimestamp</fieldName>
                        <timeZone>Europe/Stockholm</timeZone>
                    </timestamp>
                    <loggerName>
                        <fieldName>appLogger</fieldName>
                    </loggerName>
                    <logLevel>
                        <fieldName>appLogLevel</fieldName>
                    </logLevel>
                    <callerData>
                        <classFieldName>callerClass</classFieldName>
                        <methodFieldName>callerMethod</methodFieldName>
                        <fileFieldName>callerFile</fileFieldName>
                        <lineFieldName>callerLine</lineFieldName>
                    </callerData>
                    <mdc/>
                    <arguments>
                        <includeNonStructuredArguments>false</includeNonStructuredArguments>
                    </arguments>
                    <stackTrace>
                        <fieldName>stack</fieldName>
                    </stackTrace>
                    <message>
                        <fieldName>msg</fieldName>
                    </message>
                </providers>
            </encoder>
        </appender>
        <root>
            <appender-ref ref="STDOUT"/>
        </root>
    </springProfile>
</configuration>

In all cases where the logstash-logback-encoder version is greater than 5.2 we see that our Spring Boot services fails to start and exits with status 0.

Anyone else experiencing similar problems?

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:12

github_iconTop GitHub Comments

26reactions
philsttrcommented, Feb 3, 2020

Thanks @duclm2609 !

While debugging your example application with logstash-logback-encoder >= v5.3, I found the following exception occurring during startup:

java.util.ServiceConfigurationError: com.fasterxml.jackson.databind.Module: Provider com.fasterxml.jackson.module.jaxb.JaxbAnnotationModule not found
	at java.base/java.util.ServiceLoader.fail(ServiceLoader.java:588)
	at java.base/java.util.ServiceLoader$LazyClassPathLookupIterator.nextProviderClass(ServiceLoader.java:1211)
	at java.base/java.util.ServiceLoader$LazyClassPathLookupIterator.hasNextService(ServiceLoader.java:1220)
	at java.base/java.util.ServiceLoader$LazyClassPathLookupIterator.hasNext(ServiceLoader.java:1264)
	at java.base/java.util.ServiceLoader$2.hasNext(ServiceLoader.java:1299)
	at java.base/java.util.ServiceLoader$3.hasNext(ServiceLoader.java:1384)
	at com.fasterxml.jackson.databind.ObjectMapper.findModules(ObjectMapper.java:1054)
	at com.fasterxml.jackson.databind.ObjectMapper.findModules(ObjectMapper.java:1038)
	at com.fasterxml.jackson.databind.ObjectMapper.findAndRegisterModules(ObjectMapper.java:1088)
	at net.logstash.logback.composite.CompositeJsonFormatter.createJsonFactory(CompositeJsonFormatter.java:129)
	at net.logstash.logback.composite.CompositeJsonFormatter.start(CompositeJsonFormatter.java:103)
	at net.logstash.logback.encoder.CompositeJsonEncoder.start(CompositeJsonEncoder.java:211)
	at ch.qos.logback.core.joran.action.NestedComplexPropertyIA.end(NestedComplexPropertyIA.java:161)
	at ch.qos.logback.core.joran.spi.Interpreter.callEndAction(Interpreter.java:309)
	at ch.qos.logback.core.joran.spi.Interpreter.endElement(Interpreter.java:193)
	at ch.qos.logback.core.joran.spi.Interpreter.endElement(Interpreter.java:179)
	at ch.qos.logback.core.joran.spi.EventPlayer.play(EventPlayer.java:62)
	at ch.qos.logback.core.joran.GenericConfigurator.doConfigure(GenericConfigurator.java:165)
	at ch.qos.logback.core.joran.GenericConfigurator.doConfigure(GenericConfigurator.java:152)
	at ch.qos.logback.core.joran.GenericConfigurator.doConfigure(GenericConfigurator.java:110)
	at ch.qos.logback.core.joran.GenericConfigurator.doConfigure(GenericConfigurator.java:53)
	at org.springframework.boot.logging.logback.LogbackLoggingSystem.configureByResourceUrl(LogbackLoggingSystem.java:178)
	at org.springframework.boot.logging.logback.LogbackLoggingSystem.loadConfiguration(LogbackLoggingSystem.java:155)
	at org.springframework.boot.logging.AbstractLoggingSystem.initializeWithConventions(AbstractLoggingSystem.java:80)
	at org.springframework.boot.logging.AbstractLoggingSystem.initialize(AbstractLoggingSystem.java:60)
	at org.springframework.boot.logging.logback.LogbackLoggingSystem.initialize(LogbackLoggingSystem.java:118)
	at org.springframework.boot.context.logging.LoggingApplicationListener.initializeSystem(LoggingApplicationListener.java:313)
	at org.springframework.boot.context.logging.LoggingApplicationListener.initialize(LoggingApplicationListener.java:288)
	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: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:76)
	at org.springframework.boot.SpringApplicationRunListeners.environmentPrepared(SpringApplicationRunListeners.java:53)
	at org.springframework.boot.SpringApplication.prepareEnvironment(SpringApplication.java:345)
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:308)
	at org.springframework.boot.builder.SpringApplicationBuilder.run(SpringApplicationBuilder.java:140)
	at org.springframework.cloud.bootstrap.BootstrapApplicationListener.bootstrapServiceContext(BootstrapApplicationListener.java:203)
	at org.springframework.cloud.bootstrap.BootstrapApplicationListener.onApplicationEvent(BootstrapApplicationListener.java:114)
	at org.springframework.cloud.bootstrap.BootstrapApplicationListener.onApplicationEvent(BootstrapApplicationListener.java:71)
	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:76)
	at org.springframework.boot.SpringApplicationRunListeners.environmentPrepared(SpringApplicationRunListeners.java:53)
	at org.springframework.boot.SpringApplication.prepareEnvironment(SpringApplication.java:345)
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:308)
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1226)
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1215)
	at com.example.debuglogbacklogstash.DebugLogbackLogstashApplication.main(DebugLogbackLogstashApplication.java:11)

Starting with logstash-logback-encoder v5.3, automatic discovery of jackson modules was enabled by default. With logstash-logback-encoder <= 5.2, the problem does not occur because automatic discovery of jackson modules does not occur by default.

The root cause is a bug in liquibase reported as CORE-3542. Basically the liquibase-core jar contains a service definition file (META-INF/services/com.fasterxml.jackson.databind.Module) that points to the com.fasterxml.jackson.module.jaxb.JaxbAnnotationModule class, which is not on the classpath. When jackson tries to load all modules via java’s ServiceLoader, a ClassNotFoundException occurs, which is then translated into the ServiceConfigurationError mentioned above.

There are three possible solutions to get this to work with the latest logstash-logback-encoder:

A) Don’t use org.liquibase:liquibase-core until CORE-3542 is fixed, since that jar has an incorrect service loader configuration file.

OR

B) Disable automatic jackson module discovery (as mentioned here) for the encoder/layout.

For example:

        <encoder class="net.logstash.logback.encoder.LoggingEventCompositeJsonEncoder">
            <findAndRegisterJacksonModules>false</findAndRegisterJacksonModules>
            ...

OR

C) Add the dependency that contains the com.fasterxml.jackson.module.jaxb.JaxbAnnotationModule class (which allows the automatic discovery to work properly):

        <dependency>
            <groupId>com.fasterxml.jackson.module</groupId>
            <artifactId>jackson-module-jaxb-annotations</artifactId>
        </dependency>

@duclm2609, Any one of these solutions will allow your example project to work with the latest logstash-logback-encoder.

@englishbobster and @PatrickHuetter , can you see if these solutions address your problems as well? I’m going to assume that it is the same problem. I’ll close this issue if I don’t hear back after a while.

0reactions
fdesucommented, Feb 27, 2020

@philsttr thanks for the analysis and an explanation

Read more comments on GitHub >

github_iconTop Results From Across the Web

Spring Boot 2.2.2.RELEASE with logstash-logback-encoder ...
RELEASE with logstash-logback-encoder Versions > 5.2 service fails ... that our Spring Boot services fails to start and exits with status 0.
Read more >
Spring Cloud Sleuth Reference Documentation
Spring Cloud Sleuth is able to trace your requests and messages so that you can correlate that communication to corresponding log entries. You...
Read more >
Springfox swagger not working in spring boot 2.2.0
I am using spring-boot 2.2.2.RELEASE and there was no issue with spring-core and swagger. Below import was the culprit
Read more >
Failed To Instantiate Type Net.Logstash.Logback.Appender ...
RELEASE with logstashlogbackencoder Versions 5.2 service fails with System.Exit 0. Hi we have tried to use Spring Boot 2.2.2.
Read more >
Cloud Native Core Licensing Information User Manual
Provider Component (s) Licensing Information Apache 2.0 akka‑cluster‑sharding 2.6.7 APACHE 2.0 ‑See Appendix E Ansible, Inc. Ansible 2.7.9‑1 Eclipse Foundation AspectJ 1.9.5
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found