Webflux Logging is a Java library for logging incoming HTTP requests in Spring WebFlux applications. It collects request data into an HttpLog model and provides the capability to write this data as a JSON string to the console. The library offers additional configuration options and extensibility through the use of custom HttpLogConsumer beans.
-
Automatic Logging: By default, the library is enabled and will log incoming requests automatically.
-
Customizable Logging: You can configure the library to ignore specific request patterns using the
logging.webflux.http.ignore-patterns
application property. This property accepts a list of string patterns, and matching is done via the AntPathMatcher. -
Extensibility: The library provides an interface named HttpLogConsumer, which allows you to register custom beans that consume HttpLog objects. This feature enables you to perform additional actions with the request data.
To include this library in your Spring WebFlux project, add the following dependency to your pom.xml
:
<dependency>
<groupId>io.github.lipiridi</groupId>
<artifactId>webflux-logging</artifactId>
<version>1.0.1</version> <!-- Replace with the latest version -->
</dependency>
By default, the library is enabled. However, you can disable it by specifying the following application property in your
application.properties
or application.yml
:
logging.webflux.http.enabled=false
To specify patterns that should be ignored for logging, use the logging.webflux.http.ignore-patterns
application
property. Provide a list of string patterns to match against incoming requests.
logging.webflux.http.ignore-patterns=/actuator/**, /swagger-ui
To perform additional actions with HttpLog
objects, you can implement the HttpLogConsumer
interface and register it
as a bean. It can be used to modify the HttpLog
before logging it or publishing it to external storage.
Here's an example of creating a custom HttpLogConsumer
:
import org.springframework.stereotype.Component;
@Component
public class CustomHttpLogConsumer implements HttpLogConsumer {
@Override
public void accept(HttpLog httpLog) {
// Custom actions with the HttpLog object
}
}
Here's an example of the JSON output that the library generates for an HTTP request:
{
"uri": "http://localhost:8080/ping?filter=123",
"path": "/ping",
"method": "POST",
"statusCode": 200,
"queryParams": {
"filter": [
"123"
]
},
"formData": {},
"requestHeaders": {
"Accept": "text/html"
},
"requestBody": {
"test": "Hello Webflux!"
},
"responseHeaders": {
"Content-Type": "text/html; charset=utf-8"
},
"responseBody": {
"result": "ok"
}
}
This project is licensed under the MIT License. See the LICENSE file for details.