Skip to content

Commit 68d587b

Browse files
authored
Introduce Spring Boot Starter (#11)
Signed-off-by: Dmitry Sulman <[email protected]>
1 parent b3e9377 commit 68d587b

File tree

34 files changed

+1024
-61
lines changed

34 files changed

+1024
-61
lines changed

README.md

Lines changed: 114 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,26 @@
55
[![CodeQL](https://github.com/dmitrysulman/logback-access-reactor-netty/actions/workflows/codeql.yml/badge.svg)](https://github.com/dmitrysulman/logback-access-reactor-netty/actions/workflows/codeql.yml)
66
[![codecov](https://codecov.io/gh/dmitrysulman/logback-access-reactor-netty/graph/badge.svg?token=LOEJQ7K8Z7)](https://codecov.io/gh/dmitrysulman/logback-access-reactor-netty)
77

8-
A Java/Kotlin library that integrates Logback Access with Reactor Netty HTTP server, providing comprehensive access logging capabilities.
8+
A Java/Kotlin library and Spring Boot Starter that integrates Logback Access with Reactor Netty HTTP server, providing comprehensive access logging capabilities for reactive web applications.
9+
10+
## Contents:
11+
12+
- [Overview](#overview)
13+
- [Features](#features)
14+
- [Usage](#usage)
15+
- [Using as a Spring Boot Starter](#using-as-a-spring-boot-starter)
16+
- [Adding Spring Boot Starter to your project](#adding-spring-boot-starter-to-your-project)
17+
- [Configuration](#configuration)
18+
- [Application properties](#application-properties)
19+
- [Profile-specific configuration](#profile-specific-configuration)
20+
- [Dependencies](#dependencies)
21+
- [Using as a standalone library](#using-as-a-standalone-library)
22+
- [Adding dependency to your project](#adding-dependency-to-your-project)
23+
- [Basic setup](#basic-setup)
24+
- [Customize Logback Access configuration](#customize-logback-access-configuration)
25+
- [Dependencies](#dependencies-1)
26+
- [API documentation](#api-documentation)
27+
- [See also](#see-also)
928

1029
## Overview
1130

@@ -17,43 +36,108 @@ A Java/Kotlin library that integrates Logback Access with Reactor Netty HTTP ser
1736

1837
## Features
1938

39+
- Spring Boot Starter with auto-configuration
2040
- XML-based configuration support
2141
- Comprehensive HTTP request/response logging
2242
- Lazy-loaded access event properties for optimal performance
2343
- Support for headers, cookies, and request parameters logging
2444
- Configurable through system properties or external configuration files
2545
- Debug mode for troubleshooting
2646

27-
## Dependencies
47+
## Usage
48+
49+
The Logback Access integration with Reactor Netty can be used in two ways:
50+
51+
1. As a Spring Boot Starter for reactive Spring Boot applications based on `spring-boot-starter-webflux`.
52+
2. As a standalone library for applications using Reactor Netty HTTP Server directly.
53+
54+
## Using as a Spring Boot Starter
55+
56+
### Adding Spring Boot Starter to your project
57+
58+
The Spring Boot Starter is published on [Maven Central](https://central.sonatype.com/artifact/io.github.dmitrysulman/logback-access-reactor-netty-spring-boot-starter). To add the dependency, use the following snippet according to your build system:
59+
60+
#### Gradle
61+
62+
```
63+
implementation("io.github.dmitrysulman:logback-access-reactor-netty-spring-boot-starter:1.1.0")
64+
```
65+
66+
#### Maven
67+
```
68+
<dependency>
69+
<groupId>io.github.dmitrysulman</groupId>
70+
<artifactId>logback-access-reactor-netty-spring-boot-starter</artifactId>
71+
<version>1.1.0</version>
72+
</dependency>
73+
```
74+
75+
### Configuration
76+
77+
Default Spring Boot auto-configuration uses the `logback-access.xml` file from the current directory or the classpath, with a fallback to the [Common Log Format](https://en.wikipedia.org/wiki/Common_Log_Format).
78+
79+
#### Application properties
80+
81+
Several application properties can be specified inside `application.properties` file or `application.yaml` file, or as command line arguments:
82+
83+
| Name | Description | Default Value |
84+
|:---------------------------------------|:--------------------------------------------------------|:---------------------|
85+
| `logback.access.reactor.netty.enabled` | Enable Logback Access Reactor Netty auto-configuration. | `true` |
86+
| `logback.access.reactor.netty.config` | Config file name. | `logback-access.xml` |
87+
| `logback.access.reactor.netty.debug` | Enable debug mode. | `false` |
88+
89+
#### Profile-specific configuration
90+
91+
The `<springProfile>` tag allows you to conditionally include or exclude parts of the configuration based on the active Spring profiles. You can use it anywhere within the `<configuration>` element. Specify the applicable profile using the `name` attribute, which can be either a single profile name (e.g., `staging`) or a profile expression. For more details, see the [Spring Boot Logback Extensions Profile-specific Configuration reference guide](https://docs.spring.io/spring-boot/reference/features/logging.html#features.logging.logback-extensions.profile-specific), which describes the same usage. There are several examples:
92+
93+
```xml
94+
<springProfile name="staging">
95+
<!-- configuration to be enabled when the "staging" profile is active -->
96+
</springProfile>
97+
98+
<springProfile name="dev | staging">
99+
<!-- configuration to be enabled when the "dev" or "staging" profiles are active -->
100+
</springProfile>
101+
102+
<springProfile name="!production">
103+
<!-- configuration to be enabled when the "production" profile is not active -->
104+
</springProfile>
105+
```
106+
107+
### Dependencies
28108

29109
- Java 17+
30110
- Kotlin Standard Library 2.1.21
31-
- Reactor Netty HTTP Server 1.2.6+ (should be explicitly provided)
111+
- Spring Boot Starter WebFlux 3.4.6+ (should be explicitly provided)
32112
- Logback-access 2.0.6
33113
- SLF4J 2.0.17
34114

35-
## Usage
115+
## Using as a standalone library
36116

37-
### Adding dependency
117+
### Adding dependency to your project
118+
119+
The library is published on [Maven Central](https://central.sonatype.com/artifact/io.github.dmitrysulman/logback-access-reactor-netty). To add the dependency, use the following snippet according to your build system:
120+
121+
##### Gradle
122+
123+
```
124+
implementation("io.github.dmitrysulman:logback-access-reactor-netty:1.1.0")
125+
```
38126

39127
#### Maven
40128

41129
```
42130
<dependency>
43131
<groupId>io.github.dmitrysulman</groupId>
44132
<artifactId>logback-access-reactor-netty</artifactId>
45-
<version>1.0.7</version>
133+
<version>1.1.0</version>
46134
</dependency>
47135
```
48136

49-
#### Gradle
50-
51-
```
52-
implementation("io.github.dmitrysulman:logback-access-reactor-netty:1.0.7")
53-
```
54-
55137
### Basic Setup
56138

139+
To enable Logback Access integration with Reactor Netty, create a new instance of `ReactorNettyAccessLogFactory` and pass it to the `HttpServer.accessLog()` method.
140+
57141
#### Java
58142

59143
```java
@@ -67,6 +151,8 @@ HttpServer.create()
67151

68152
#### Kotlin
69153

154+
For Kotlin, a convenient [enableLogbackAccess()](https://dmitrysulman.github.io/logback-access-reactor-netty/logback-access-reactor-netty/io.github.dmitrysulman.logback.access.reactor.netty/enable-logback-access.html) extension function is provided to pass the factory instance.
155+
70156
```kotlin
71157
val factory = ReactorNettyAccessLogFactory()
72158
HttpServer.create()
@@ -76,13 +162,14 @@ HttpServer.create()
76162
.block()
77163
```
78164

79-
### Configuration
165+
### Customize Logback Access configuration
80166

81167
The library can be configured in several ways:
82168

83-
1. **Default configuration** uses the `logback-access.xml` file from the classpath or the current directory, with a fallback to the [Common Log Format](https://en.wikipedia.org/wiki/Common_Log_Format).
169+
1. **Default configuration** uses the `logback-access.xml` file from the current directory or the classpath, with a fallback to the [Common Log Format](https://en.wikipedia.org/wiki/Common_Log_Format).
84170
2. **System property.** Set `-Dlogback.access.reactor.netty.config` property to specify configuration file location.
85171
3. **Programmatic configuration.** Provide configuration file filename or URL of the classpath resource directly:
172+
86173
```java
87174
// Using specific configuration file by the filename
88175
var factory = new ReactorNettyAccessLogFactory("/path/to/logback-access.xml");
@@ -93,44 +180,25 @@ var factory = new ReactorNettyAccessLogFactory(
93180
);
94181
```
95182

96-
### Spring Boot configuration
97-
98-
#### Java
183+
### Dependencies
99184

100-
```java
101-
@Configuration
102-
public class NettyAccessLogConfiguration {
103-
@Bean
104-
public NettyServerCustomizer accessLogNettyServerCustomizer() {
105-
return (server) ->
106-
server.accessLog(true, new ReactorNettyAccessLogFactory("path/to/your/logback-access.xml"));
107-
}
108-
}
109-
```
110-
111-
#### Kotlin
112-
```kotlin
113-
@Configuration
114-
class NettyAccessLogConfiguration {
115-
@Bean
116-
fun accessLogNettyServerCustomizer() =
117-
NettyServerCustomizer { server ->
118-
server.enableLogbackAccess(ReactorNettyAccessLogFactory("path/to/your/logback-access.xml"))
119-
}
120-
}
121-
```
122-
See [enableLogbackAccess()](https://dmitrysulman.github.io/logback-access-reactor-netty/logback-access-reactor-netty/io.github.dmitrysulman.logback.access.reactor.netty/enable-logback-access.html) extension function documentation.
185+
- Java 17+
186+
- Kotlin Standard Library 2.1.21
187+
- Reactor Netty HTTP Server 1.2.6+ (should be explicitly provided)
188+
- Logback-access 2.0.6
189+
- SLF4J 2.0.17
123190

124-
## Documentation
191+
## API documentation
125192

126-
- [Java API (Javadoc)](https://javadoc.io/doc/io.github.dmitrysulman/logback-access-reactor-netty/latest/index.html)
193+
- [Java API (Javadoc) - Spring Boot Starter](https://javadoc.io/doc/io.github.dmitrysulman/logback-access-reactor-netty-spring-boot-starter/latest/index.html)
194+
- [Java API (Javadoc) - Standalone library](https://javadoc.io/doc/io.github.dmitrysulman/logback-access-reactor-netty/latest/index.html)
127195
- [Kotlin API (KDoc)](https://dmitrysulman.github.io/logback-access-reactor-netty/)
128196

129-
## Author
130-
131-
[Dmitry Sulman](https://www.linkedin.com/in/dmitrysulman/)
132-
133197
## See Also
134198

135199
- [Reactor Netty HTTP Server Documentation](https://projectreactor.io/docs/netty/release/reference/http-server.html)
136200
- [Logback Access Documentation](https://logback.qos.ch/access.html)
201+
202+
## Author
203+
204+
[Dmitry Sulman](https://www.linkedin.com/in/dmitrysulman/)

build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ group = "io.github.dmitrysulman"
1313

1414
dependencies {
1515
dokka(project("logback-access-reactor-netty"))
16+
dokka(project("logback-access-reactor-netty-spring-boot-starter"))
1617
}
1718

1819
tasks.jreleaserFullRelease {

buildSrc/src/main/kotlin/conventions.gradle.kts

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -84,16 +84,24 @@ dokka {
8484
}
8585
externalDocumentationLinks {
8686
register("reactor-netty-docs") {
87-
url("https://projectreactor.io/docs/netty/${libs.versions.reactorNetty.get()}/api/")
88-
packageListUrl("https://projectreactor.io/docs/netty/${libs.versions.reactorNetty.get()}/api/package-list")
87+
url("https://projectreactor.io/docs/netty/release/api/")
88+
packageListUrl("https://projectreactor.io/docs/netty/release/api/package-list")
8989
}
9090
register("logback-access-docs") {
91-
url("https://javadoc.io/doc/ch.qos.logback.access/logback-access-common/${libs.versions.logbackAccess.get()}/")
92-
packageListUrl("https://javadoc.io/doc/ch.qos.logback.access/logback-access-common/${libs.versions.logbackAccess.get()}/element-list")
91+
url("https://javadoc.io/doc/ch.qos.logback.access/logback-access-common/latest/")
92+
packageListUrl("https://javadoc.io/doc/ch.qos.logback.access/logback-access-common/latest/element-list")
9393
}
9494
register("logback-core-docs") {
95-
url("https://javadoc.io/doc/ch.qos.logback/logback-core/${libs.versions.logbackClassic.get()}/")
96-
packageListUrl("https://javadoc.io/doc/ch.qos.logback/logback-core/${libs.versions.logbackClassic.get()}/element-list")
95+
url("https://javadoc.io/doc/ch.qos.logback/logback-core/latest/")
96+
packageListUrl("https://javadoc.io/doc/ch.qos.logback/logback-core/latest/element-list")
97+
}
98+
register("spring-framework-docs") {
99+
url("https://docs.spring.io/spring-framework/docs/current/javadoc-api/")
100+
packageListUrl("https://docs.spring.io/spring-framework/docs/current/javadoc-api/element-list")
101+
}
102+
register("spring-boot-docs") {
103+
url("https://docs.spring.io/spring-boot/api/java/")
104+
packageListUrl("https://docs.spring.io/spring-boot/api/java/element-list")
97105
}
98106
}
99107
}

gradle.properties

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
version=1.0.8-SNAPSHOT
1+
version=1.1.0-SNAPSHOT
22
org.gradle.caching=true
33
org.gradle.configuration-cache=false
44
org.gradle.jvmargs=-Xmx2g
55
org.jetbrains.dokka.experimental.gradle.pluginMode=V2Enabled
6-
org.jetbrains.dokka.experimental.gradle.pluginMode.noWarn=true
6+
org.jetbrains.dokka.experimental.gradle.pluginMode.noWarn=true
7+
kapt.use.k2=true

gradle/libs.versions.toml

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
[versions]
2+
assertj = "3.27.3"
23
dokka = "2.0.0"
34
jackson = "2.19.0"
45
java = "17"
@@ -14,8 +15,10 @@ logbackClassic = "1.5.18"
1415
mockk = "1.14.2"
1516
reactorNetty = "1.2.7"
1617
slf4j = "2.0.17"
18+
springBoot = "3.4.6"
1719

1820
[libraries]
21+
assertj-core = { group = "org.assertj", name = "assertj-core", version.ref = "assertj" }
1922
dokka-plugin = { group = "org.jetbrains.dokka", name = "org.jetbrains.dokka.gradle.plugin", version.ref = "dokka" }
2023
dokka-javadoc-plugin = { group = "org.jetbrains.dokka-javadoc", name = "org.jetbrains.dokka-javadoc.gradle.plugin", version.ref = "dokka" }
2124
jackson-bom = { group = "com.fasterxml.jackson", name = "jackson-bom", version.ref = "jackson" }
@@ -31,7 +34,15 @@ logback-classic = { group = "ch.qos.logback", name = "logback-classic", version.
3134
mockk = { group = "io.mockk", name = "mockk", version.ref = "mockk" }
3235
reactorNetty-http = { group = "io.projectreactor.netty", name = "reactor-netty-http", version.ref = "reactorNetty" }
3336
slf4j-api = { group = "org.slf4j", name = "slf4j-api", version.ref = "slf4j" }
37+
spring-boot-autoconfigureProcessor = { group = "org.springframework.boot", name = "spring-boot-autoconfigure-processor", version.ref = "springBoot" }
38+
spring-boot-configurationProcessor = { group = "org.springframework.boot", name = "spring-boot-configuration-processor", version.ref = "springBoot" }
39+
spring-boot-starter = { group = "org.springframework.boot", name = "spring-boot-starter", version.ref = "springBoot" }
40+
spring-boot-starter-reactorNetty = { group = "org.springframework.boot", name = "spring-boot-starter-reactor-netty", version.ref = "springBoot" }
41+
spring-boot-starter-test = { group = "org.springframework.boot", name = "spring-boot-starter-test", version.ref = "springBoot" }
42+
spring-boot-starter-webflux = { group = "org.springframework.boot", name = "spring-boot-starter-webflux", version.ref = "springBoot" }
3443

3544
[plugins]
3645
dokka = { id = "org.jetbrains.dokka" }
37-
jreleaser = { id = "org.jreleaser", version.ref = "jreleaser" }
46+
conventions = { id = "conventions" }
47+
jreleaser = { id = "org.jreleaser", version.ref = "jreleaser" }
48+
kotlin-springPlugin = { id = "org.jetbrains.kotlin.plugin.spring", version.ref = "kotlin" }
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
plugins {
2+
alias(libs.plugins.conventions)
3+
alias(libs.plugins.kotlin.springPlugin)
4+
kotlin("kapt")
5+
}
6+
7+
description = "Spring Boot Starter for Logback Access integration with Reactor Netty"
8+
9+
dependencies {
10+
api(project(":logback-access-reactor-netty"))
11+
12+
implementation(libs.spring.boot.starter)
13+
implementation(libs.slf4j.api)
14+
15+
provided(libs.spring.boot.starter.reactorNetty)
16+
17+
kapt(libs.spring.boot.autoconfigureProcessor)
18+
kapt(libs.spring.boot.configurationProcessor)
19+
20+
testImplementation(libs.assertj.core)
21+
testImplementation(libs.kotest.assertions.core.jvm)
22+
testImplementation(libs.mockk)
23+
testImplementation(libs.spring.boot.starter.test)
24+
testImplementation(libs.spring.boot.starter.webflux)
25+
}

0 commit comments

Comments
 (0)