Reusable JSON logging library for Spring Boot and MuleSoft. Built on Logback with a chain-of-responsibility enricher pattern.
mvn clean install<dependency>
<groupId>com.viz.logger</groupId>
<artifactId>mulesoft-json-logger</artifactId>
<version>1.0.0</version>
</dependency>The file is included in this project under src/main/resources/logback-spring.xml.
| Class | Responsibility |
|---|---|
JsonLogEncoder |
Logback encoder — converts event → JSON bytes |
FieldExtractor |
Base fields: @timestamp, level, thread, logger, message |
MdcEnricher |
MDC map → top-level JSON fields |
ExceptionEnricher |
Throwable → { error: { type, message, stacktrace } } |
StaticFieldsEnricher |
appName, env, hostname, pid |
PiiMaskingEnricher |
Masks email, phone, credit card in all string fields |
MdcRequestFilter |
Spring HTTP filter — populates MDC per request |
MdcTaskDecorator |
Spring TaskDecorator — propagates MDC to @Async tasks |
LogContextBuilder |
Fluent API for building MDC context |
<encoder class="com.viz.logger.encoder.JsonLogEncoder">
<appName>order-service</appName>
<environment>prod</environment>
<maskPii>true</maskPii>
<includeAllMdc>true</includeAllMdc>
</encoder>try (LogContext ctx = LogContextBuilder.forRequest(httpRequest)
.userId("42")
.orderId("777")
.service("order-service")
.build()) {
log.info("This line has full MDC context in JSON");
}
// MDC.clear() is called automatically{
"@timestamp": "2025-04-22T10:15:33.421Z",
"level": "INFO",
"levelValue": 20000,
"thread": "http-nio-8080-exec-3",
"logger": "com.example.OrderService",
"message": "Order created",
"requestId": "abc-123",
"traceId": "550e8400-e29b-41d4-a716-446655440000",
"userId": "42",
"method": "POST",
"uri": "/api/v1/orders",
"appName": "order-service",
"env": "prod",
"hostname": "prod-node-42",
"pid": 12345
}