logback-access-spring-boot-starter
logback-access-spring-boot-starter copied to clipboard
Spring Boot Embedded Tomcat NullPointerException get-serverName
Describe the bug
Running locally using an IDEA results in NullPointerExceptions when attempting to log.
Spring Boot Dependencies: Spring Boot Starter Parent 2.6.0 with Tomcat
logback-access.xml
<configuration>
<statusListener class="ch.qos.logback.core.status.OnConsoleStatusListener"/>
<appender name="logstash-access" class="ch.qos.logback.core.ConsoleAppender">
<encoder class="net.logstash.logback.encoder.LogstashAccessEncoder">
<fieldNames>
<requestHeaders>request_headers</requestHeaders>
<responseHeaders>response_headers</responseHeaders>
<requestedUrl>requested_url</requestedUrl>
<statusCode>status_code</statusCode>
</fieldNames>
<requestHeaderFilter class="a.package.LogstashHeaderFilter">
<exclude>Authorization</exclude>
</requestHeaderFilter>
</encoder>
</appender>
<appender-ref ref="logstash-access"/>
</configuration>
Log
09:49:00,681 |-ERROR in ch.qos.logback.core.ConsoleAppender[logstash-access] - Appender [logstash-access] failed to append. java.lang.NullPointerException: <get-serverName>(...) must not be null
at java.lang.NullPointerException: <get-serverName>(...) must not be null
at at dev.akkinoc.spring.boot.logback.access.tomcat.LogbackAccessTomcatEventSource.getServerName(LogbackAccessTomcatEventSource.kt:53)
at at dev.akkinoc.spring.boot.logback.access.LogbackAccessEventSource$Fixed.<init>(LogbackAccessEventSource.kt:181)
at at dev.akkinoc.spring.boot.logback.access.LogbackAccessEventSource.fix(LogbackAccessEventSource.kt:156)
at at dev.akkinoc.spring.boot.logback.access.LogbackAccessEvent.prepareForDeferredProcessing(LogbackAccessEvent.kt:159)
To Reproduce
- Create a default spring boot app with a hello controller
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.6.0</version>
</parent>
- Add the logback related dependencies
<dependency>
<groupId>net.logstash.logback</groupId>
<artifactId>logstash-logback-encoder</artifactId>
<version>${logback-encoder.version}</version>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>${logback.version}</version>
</dependency>
<dependency>
<groupId>dev.akkinoc.spring.boot</groupId>
<artifactId>logback-access-spring-boot-starter</artifactId>
<version>3.1.0</version>
</dependency>
- Add the logback-access.xml file specified above
- Start up the application
- Hit the hello controller
Expected behavior
Normal logging behavior to continue or for documentation to be available concerning upgrading the major version.
Environment
- Version of this library used: 3.0.0 and 3.1.0
- Version of Java used: Java 11 and Java 17
Thank you for the report.
I couldn't reproduce it in my environment... Would you please provide the following information?
- Minimum sample project that can reproduce this issue
- The hostname of the environment that can reproduce this issue
- HTTP request content (including header) that can reproduce this issue
I haven't commented for awhile on this but I'll work next week on getting a reproduction of this issue to you.
This issue is inactive, so I close it. If you still have problems, please open a new issue.