Skip to content

Commit 1ffb8f3

Browse files
authored
Merge pull request #336 from akkinoc/v4
Release version 4 to support Spring Boot 3
2 parents 3ec47a3 + e9c9d56 commit 1ffb8f3

File tree

54 files changed

+367
-179
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+367
-179
lines changed

.github/workflows/build.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ jobs:
55
strategy:
66
fail-fast: false
77
matrix:
8-
java: [8, 11, 17]
8+
java: [17]
99
name: Build with Java ${{ matrix.java }}
1010
runs-on: ubuntu-20.04
1111
steps:

README.md

+7-7
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,10 @@ Supports the following web servers:
5050

5151
Depends on:
5252

53-
* Java 8, 11 or 17
54-
* Kotlin 1.6
55-
* Spring Boot 2.7
56-
* Logback-access 1.2
53+
* Java 17
54+
* Kotlin 1.7
55+
* Spring Boot 3.0
56+
* Logback-access 1.4
5757

5858
## Usage
5959

@@ -90,7 +90,7 @@ For example:
9090

9191
See also the Logback-access official documents:
9292

93-
* [Logback-access configuration](https://logback.qos.ch/access.html#configuration)
93+
* [Logback-access configuration](https://logback.qos.ch/access.html)
9494

9595
### Access Logging
9696

@@ -134,7 +134,7 @@ This is the same concept as the [Logback configuration ("logback.xml" and "logba
134134
The `<springProfile>` tag lets you optionally include or exclude sections of configuration based on the active Spring profiles.
135135
The usage of this extension is the same as the [Spring Boot Logback Extension "Profile-specific Configuration"].
136136

137-
[Spring Boot Logback Extension "Profile-specific Configuration"]: https://docs.spring.io/spring-boot/docs/2.5.6/reference/html/features.html#features.logging.logback-extensions.profile-specific
137+
[Spring Boot Logback Extension "Profile-specific Configuration"]: https://docs.spring.io/spring-boot/docs/3.0.6/reference/html/features.html#features.logging.logback-extensions.profile-specific
138138

139139
> ```xml
140140
> <springProfile name="staging">
@@ -153,7 +153,7 @@ The usage of this extension is the same as the [Spring Boot Logback Extension "P
153153
The `<springProperty>` tag lets you expose properties from the Spring Environment for use within Logback.
154154
The usage of this extension is the same as the [Spring Boot Logback Extension "Environment Properties"].
155155
156-
[Spring Boot Logback Extension "Environment Properties"]: https://docs.spring.io/spring-boot/docs/2.5.6/reference/html/features.html#features.logging.logback-extensions.environment-properties
156+
[Spring Boot Logback Extension "Environment Properties"]: https://docs.spring.io/spring-boot/docs/3.0.6/reference/html/features.html#features.logging.logback-extensions.environment-properties
157157
158158
> ```xml
159159
> <springProperty scope="context" name="fluentHost" source="myapp.fluentd.host" defaultValue="localhost"/>

examples/webflux-jetty-java/pom.xml

+3-2
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,12 @@
1313
<parent>
1414
<groupId>org.springframework.boot</groupId>
1515
<artifactId>spring-boot-starter-parent</artifactId>
16-
<version>2.7.11</version>
16+
<version>3.0.6</version>
1717
</parent>
1818

1919
<properties>
20-
<logback-access-spring-boot-starter.version>[3.0.0,)</logback-access-spring-boot-starter.version>
20+
<jakarta-servlet.version>5.0.0</jakarta-servlet.version>
21+
<logback-access-spring-boot-starter.version>[4.0.0,)</logback-access-spring-boot-starter.version>
2122
</properties>
2223

2324
<dependencies>

examples/webflux-tomcat-java/pom.xml

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@
1313
<parent>
1414
<groupId>org.springframework.boot</groupId>
1515
<artifactId>spring-boot-starter-parent</artifactId>
16-
<version>2.7.11</version>
16+
<version>3.0.6</version>
1717
</parent>
1818

1919
<properties>
20-
<logback-access-spring-boot-starter.version>[3.0.0,)</logback-access-spring-boot-starter.version>
20+
<logback-access-spring-boot-starter.version>[4.0.0,)</logback-access-spring-boot-starter.version>
2121
</properties>
2222

2323
<dependencies>

examples/webflux-undertow-java/pom.xml

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@
1313
<parent>
1414
<groupId>org.springframework.boot</groupId>
1515
<artifactId>spring-boot-starter-parent</artifactId>
16-
<version>2.7.11</version>
16+
<version>3.0.6</version>
1717
</parent>
1818

1919
<properties>
20-
<logback-access-spring-boot-starter.version>[3.0.0,)</logback-access-spring-boot-starter.version>
20+
<logback-access-spring-boot-starter.version>[4.0.0,)</logback-access-spring-boot-starter.version>
2121
</properties>
2222

2323
<dependencies>

examples/webmvc-jetty-java/pom.xml

+3-2
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,12 @@
1313
<parent>
1414
<groupId>org.springframework.boot</groupId>
1515
<artifactId>spring-boot-starter-parent</artifactId>
16-
<version>2.7.11</version>
16+
<version>3.0.6</version>
1717
</parent>
1818

1919
<properties>
20-
<logback-access-spring-boot-starter.version>[3.0.0,)</logback-access-spring-boot-starter.version>
20+
<jakarta-servlet.version>5.0.0</jakarta-servlet.version>
21+
<logback-access-spring-boot-starter.version>[4.0.0,)</logback-access-spring-boot-starter.version>
2122
</properties>
2223

2324
<dependencies>

examples/webmvc-tomcat-java/pom.xml

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@
1313
<parent>
1414
<groupId>org.springframework.boot</groupId>
1515
<artifactId>spring-boot-starter-parent</artifactId>
16-
<version>2.7.11</version>
16+
<version>3.0.6</version>
1717
</parent>
1818

1919
<properties>
20-
<logback-access-spring-boot-starter.version>[3.0.0,)</logback-access-spring-boot-starter.version>
20+
<logback-access-spring-boot-starter.version>[4.0.0,)</logback-access-spring-boot-starter.version>
2121
</properties>
2222

2323
<dependencies>

examples/webmvc-tomcat-kotlin/pom.xml

+3-3
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@
1313
<parent>
1414
<groupId>org.springframework.boot</groupId>
1515
<artifactId>spring-boot-starter-parent</artifactId>
16-
<version>2.7.11</version>
16+
<version>3.0.6</version>
1717
</parent>
1818

1919
<properties>
20-
<logback-access-spring-boot-starter.version>[3.0.0,)</logback-access-spring-boot-starter.version>
20+
<logback-access-spring-boot-starter.version>[4.0.0,)</logback-access-spring-boot-starter.version>
2121
</properties>
2222

2323
<dependencies>
@@ -62,7 +62,7 @@
6262
</dependencies>
6363
<configuration>
6464
<compilerPlugins>
65-
<compilerPlugin>spring</compilerPlugin>
65+
<plugin>spring</plugin>
6666
</compilerPlugins>
6767
</configuration>
6868
</plugin>

examples/webmvc-undertow-java/pom.xml

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@
1313
<parent>
1414
<groupId>org.springframework.boot</groupId>
1515
<artifactId>spring-boot-starter-parent</artifactId>
16-
<version>2.7.11</version>
16+
<version>3.0.6</version>
1717
</parent>
1818

1919
<properties>
20-
<logback-access-spring-boot-starter.version>[3.0.0,)</logback-access-spring-boot-starter.version>
20+
<logback-access-spring-boot-starter.version>[4.0.0,)</logback-access-spring-boot-starter.version>
2121
</properties>
2222

2323
<dependencies>

pom.xml

+9-3
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
<groupId>dev.akkinoc.spring.boot</groupId>
1010
<artifactId>logback-access-spring-boot-starter</artifactId>
11-
<version>3.4.7-SNAPSHOT</version>
11+
<version>4.0.0</version>
1212

1313
<name>logback-access-spring-boot-starter</name>
1414
<description>Spring Boot Starter for Logback-access.</description>
@@ -17,7 +17,7 @@
1717
<parent>
1818
<groupId>org.springframework.boot</groupId>
1919
<artifactId>spring-boot-starter-parent</artifactId>
20-
<version>2.7.11</version>
20+
<version>3.0.6</version>
2121
</parent>
2222

2323
<organization>
@@ -135,6 +135,12 @@
135135
<artifactId>spring-boot-starter-test</artifactId>
136136
<scope>test</scope>
137137
</dependency>
138+
<dependency>
139+
<groupId>jakarta.servlet</groupId>
140+
<artifactId>jakarta.servlet-api</artifactId>
141+
<version>5.0.0</version>
142+
<scope>test</scope>
143+
</dependency>
138144
<dependency>
139145
<groupId>io.kotest</groupId>
140146
<artifactId>kotest-assertions-core-jvm</artifactId>
@@ -205,7 +211,7 @@
205211
</dependencies>
206212
<configuration>
207213
<compilerPlugins>
208-
<compilerPlugin>spring</compilerPlugin>
214+
<plugin>spring</plugin>
209215
</compilerPlugins>
210216
</configuration>
211217
</plugin>

src/main/kotlin/dev/akkinoc/spring/boot/logback/access/LogbackAccessContext.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class LogbackAccessContext(
2828
/**
2929
* The raw Logback-access context.
3030
*/
31-
private val raw: AccessContext = AccessContext()
31+
val raw: AccessContext = AccessContext()
3232

3333
init {
3434
val (name, resource) = run {

src/main/kotlin/dev/akkinoc/spring/boot/logback/access/LogbackAccessEvent.kt

+6-2
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@ import ch.qos.logback.access.spi.IAccessEvent
44
import ch.qos.logback.access.spi.IAccessEvent.NA
55
import ch.qos.logback.access.spi.IAccessEvent.SENTINEL
66
import ch.qos.logback.access.spi.ServerAdapter
7+
import jakarta.servlet.http.HttpServletRequest
8+
import jakarta.servlet.http.HttpServletResponse
79
import java.io.IOException
810
import java.io.ObjectOutputStream
911
import java.io.Serializable
1012
import java.util.Collections.enumeration
1113
import java.util.Enumeration
1214
import java.util.concurrent.TimeUnit.MILLISECONDS
13-
import javax.servlet.http.HttpServletRequest
14-
import javax.servlet.http.HttpServletResponse
1515

1616
/**
1717
* The Logback-access event.
@@ -46,6 +46,10 @@ class LogbackAccessEvent(private var source: LogbackAccessEventSource) : IAccess
4646
return MILLISECONDS.toSeconds(millis)
4747
}
4848

49+
override fun getSequenceNumber(): Long {
50+
return source.sequenceNumber ?: 0L
51+
}
52+
4953
override fun getThreadName(): String {
5054
return source.threadName
5155
}

src/main/kotlin/dev/akkinoc/spring/boot/logback/access/LogbackAccessEventSource.kt

+9-2
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ package dev.akkinoc.spring.boot.logback.access
22

33
import ch.qos.logback.access.spi.IAccessEvent
44
import ch.qos.logback.access.spi.ServerAdapter
5+
import jakarta.servlet.http.HttpServletRequest
6+
import jakarta.servlet.http.HttpServletResponse
57
import java.io.Serializable
6-
import javax.servlet.http.HttpServletRequest
7-
import javax.servlet.http.HttpServletResponse
88

99
/**
1010
* The Logback-access event source.
@@ -40,6 +40,11 @@ abstract class LogbackAccessEventSource {
4040
*/
4141
abstract val elapsedTime: Long?
4242

43+
/**
44+
* The value of [IAccessEvent.getSequenceNumber].
45+
*/
46+
abstract val sequenceNumber: Long?
47+
4348
/**
4449
* The value of [IAccessEvent.getThreadName].
4550
*/
@@ -176,6 +181,8 @@ abstract class LogbackAccessEventSource {
176181

177182
override val elapsedTime: Long? = source.elapsedTime
178183

184+
override val sequenceNumber: Long? = source.sequenceNumber
185+
179186
override val threadName: String = source.threadName
180187

181188
override val serverName: String = source.serverName

src/main/kotlin/dev/akkinoc/spring/boot/logback/access/LogbackAccessProperties.kt

-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import dev.akkinoc.spring.boot.logback.access.value.LogbackAccessLocalPortStrate
55
import io.undertow.UndertowOptions
66
import org.apache.catalina.valves.RemoteIpValve
77
import org.springframework.boot.context.properties.ConfigurationProperties
8-
import org.springframework.boot.context.properties.ConstructorBinding
98

109
/**
1110
* The configuration properties for Logback-access.
@@ -31,7 +30,6 @@ import org.springframework.boot.context.properties.ConstructorBinding
3130
* The properties for the tee filter.
3231
*/
3332
@ConfigurationProperties("logback.access")
34-
@ConstructorBinding
3533
data class LogbackAccessProperties
3634
@JvmOverloads
3735
constructor(

src/main/kotlin/dev/akkinoc/spring/boot/logback/access/jetty/LogbackAccessJettyEventSource.kt

+6-3
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import ch.qos.logback.access.AccessConstants.LB_OUTPUT_BUFFER
55
import ch.qos.logback.access.jetty.JettyServerAdapter
66
import ch.qos.logback.access.servlet.Util.isFormUrlEncoded
77
import ch.qos.logback.access.servlet.Util.isImageResponse
8+
import dev.akkinoc.spring.boot.logback.access.LogbackAccessContext
89
import dev.akkinoc.spring.boot.logback.access.LogbackAccessEventSource
910
import dev.akkinoc.spring.boot.logback.access.security.LogbackAccessSecurityServletFilter.Companion.REMOTE_USER_ATTRIBUTE
1011
import dev.akkinoc.spring.boot.logback.access.value.LogbackAccessLocalPortStrategy
@@ -20,16 +21,16 @@ import kotlin.text.Charsets.UTF_8
2021
/**
2122
* The Logback-access event source for the Jetty web server.
2223
*
23-
* @property localPortStrategy The strategy to change the behavior of [localPort].
24+
* @property logbackAccessContext The Logback-access context.
2425
* @see ch.qos.logback.access.spi.AccessEvent
2526
* @see ch.qos.logback.access.jetty.JettyServerAdapter
2627
* @see ch.qos.logback.access.PatternLayout
2728
* @see org.eclipse.jetty.server.CustomRequestLog
2829
*/
2930
class LogbackAccessJettyEventSource(
31+
private val logbackAccessContext: LogbackAccessContext,
3032
override val request: Request,
3133
override val response: Response,
32-
private val localPortStrategy: LogbackAccessLocalPortStrategy,
3334
) : LogbackAccessEventSource() {
3435

3536
override val serverAdapter: JettyServerAdapter = JettyServerAdapter(request, response)
@@ -38,14 +39,16 @@ class LogbackAccessJettyEventSource(
3839

3940
override val elapsedTime: Long = timeStamp - request.timeStamp
4041

42+
override val sequenceNumber: Long? = logbackAccessContext.raw.sequenceNumberGenerator?.nextSequenceNumber()
43+
4144
override val threadName: String = currentThread().name
4245

4346
override val serverName: String by lazy(LazyThreadSafetyMode.NONE) {
4447
request.serverName
4548
}
4649

4750
override val localPort: Int by lazy(LazyThreadSafetyMode.NONE) {
48-
when (localPortStrategy) {
51+
when (logbackAccessContext.properties.localPortStrategy) {
4952
LogbackAccessLocalPortStrategy.LOCAL -> request.localPort
5053
LogbackAccessLocalPortStrategy.SERVER -> request.serverPort
5154
}

src/main/kotlin/dev/akkinoc/spring/boot/logback/access/jetty/LogbackAccessJettyRequestLog.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@ class LogbackAccessJettyRequestLog(
2929
logbackAccessContext,
3030
)
3131
val source = LogbackAccessJettyEventSource(
32+
logbackAccessContext = logbackAccessContext,
3233
request = request,
3334
response = response,
34-
localPortStrategy = logbackAccessContext.properties.localPortStrategy,
3535
)
3636
val event = LogbackAccessEvent(source)
3737
logbackAccessContext.emit(event)
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
package dev.akkinoc.spring.boot.logback.access.joran
22

33
import ch.qos.logback.access.joran.JoranConfigurator
4-
import ch.qos.logback.core.joran.action.NOPAction
54
import ch.qos.logback.core.joran.spi.ElementSelector
65
import ch.qos.logback.core.joran.spi.RuleStore
6+
import ch.qos.logback.core.model.processor.DefaultProcessor
77
import org.springframework.core.env.Environment
88

99
/**
@@ -14,20 +14,21 @@ import org.springframework.core.env.Environment
1414
*/
1515
class LogbackAccessJoranConfigurator(private val environment: Environment) : JoranConfigurator() {
1616

17-
override fun addInstanceRules(store: RuleStore) {
18-
super.addInstanceRules(store)
19-
store.addRule(
20-
ElementSelector("*/springProfile"),
21-
LogbackAccessJoranSpringProfileAction(environment),
22-
)
23-
store.addRule(
24-
ElementSelector("*/springProfile/*"),
25-
NOPAction(),
26-
)
27-
store.addRule(
28-
ElementSelector("configuration/springProperty"),
29-
LogbackAccessJoranSpringPropertyAction(environment),
30-
)
17+
override fun addElementSelectorAndActionAssociations(store: RuleStore) {
18+
super.addElementSelectorAndActionAssociations(store)
19+
store.addRule(ElementSelector("configuration/springProperty")) { LogbackAccessJoranSpringPropertyAction() }
20+
store.addRule(ElementSelector("*/springProfile")) { LogbackAccessJoranSpringProfileAction() }
21+
store.addTransparentPathPart("springProfile")
22+
}
23+
24+
override fun addModelHandlerAssociations(processor: DefaultProcessor) {
25+
processor.addHandler(LogbackAccessJoranSpringPropertyModel::class.java) { _, _ ->
26+
LogbackAccessJoranSpringPropertyModelHandler(context, environment)
27+
}
28+
processor.addHandler(LogbackAccessJoranSpringProfileModel::class.java) { _, _ ->
29+
LogbackAccessJoranSpringProfileModelHandler(context, environment)
30+
}
31+
super.addModelHandlerAssociations(processor)
3132
}
3233

3334
}

0 commit comments

Comments
 (0)