DEV Community

Cover image for Spring Boot LogX — Free Request Tracing & Smart Logging Boilerplate for Clean, Debuggable APIs
boiler_agents
boiler_agents

Posted on

Spring Boot LogX — Free Request Tracing & Smart Logging Boilerplate for Clean, Debuggable APIs

TL;DR: LogX is a free Spring Boot starter that adds automatic requestId tracing, structured error handling, and clean log correlation so you can debug APIs faster.


Introduction

If you’ve ever opened your logs and felt overwhelmed by chaotic, mixed-up log lines, you’re not alone.

Spring Boot LogX solves log traceability problems by assigning a unique requestId to every incoming API call and injecting it into your logs, responses, and error payloads.

This boilerplate is ideal for beginners, backend engineers, small teams, and anyone building new Spring Boot services who wants better observability without writing the plumbing from scratch.


Why this boilerplate?

  • Saves time: Includes a ready-to-use logging setup so you don’t write filters, handlers, and MDC code manually.
  • Production-ready: Daily rolling file logs, consistent error models, and request correlation built in.
  • Opinionated best-practices: Uses MDC, a request filter, structured logging pattern, and centralized error handling.
  • Includes:
    • Automatic requestId injection
    • Demo endpoints
    • Postman collection
    • Logback config (console + file logging)

Features

  • RequestIdFilter — assigns a unique ID to every request
  • MDC-based logging — requestId appears in every log line
  • GlobalExceptionHandler — consistent error responses with requestId
  • Daily rolling file logs — realistic production-ready logging
  • Demo APIs — instantly testable
  • Postman Collection — for quick verification
  • Docker-ready structure — easy to containerize

Prerequisites

  • Java 17+
  • Maven 3.8+
  • Docker (optional for containerized runs)

Quick Start (Install & Run)

Setup locally

  • Download the free ZIP from Gumroad and extract it
  • Open in your IDE (IntelliJ, Eclipse, VS Code, etc.)
  • Customize the code if needed
  • Run the Spring Boot app or package a JAR

Usage & Examples

Use provided Postman Collection

Sample API request

GET /api/demo/echo?msg=hello
Enter fullscreen mode Exit fullscreen mode

Sample response:

{
  "message": "hello",
  "requestId": "a2f7f8c0-1c33-45cf-9b9e-3b2d909e5fa0"
}
Enter fullscreen mode Exit fullscreen mode

Error (demo)

curl http://localhost:8080/api/demo/error
Enter fullscreen mode Exit fullscreen mode

Example output:

{
  "timestamp": "2025-11-13T10:12:45.218",
  "status": 500,
  "errorCode": "INTERNAL_ERROR",
  "message": "Something went wrong",
  "path": "/api/demo/error",
  "requestId": "d8bf7a12-1e9f-4218-bc4d-b2c6a657ac80"
}
Enter fullscreen mode Exit fullscreen mode

Now you can search your logs for that same requestId.


Configuration

Important config files

  • logback-spring.xml — centralized logging setup
  • application.properties — Spring Boot config
  • Environment variables (optional):

    • LOG_DIR
    • Spring profiles

Example logback entry:

<property name="LOG_PATTERN"
  value="%d{yyyy-MM-dd HH:mm:ss.SSS} %-5level %logger{36} - %msg [requestId=%X{requestId}]%n"/>
Enter fullscreen mode Exit fullscreen mode

This is what creates clean, traceable logs.


Project Structure

spring-boot-logx/
├── src/main/java/com/logx/
│   ├── controller/            # Demo controllers
│   ├── exception/             # GlobalExceptionHandler + custom exceptions
│   ├── filter/                # RequestIdFilter
│   ├── model/                 # ErrorResponse
│   └── util/                  # LogUtils (MDC helper)
├── src/main/resources/
│   └── logback-spring.xml     # Logging configuration
└── spring-boot-logx.postman_collection.json
Enter fullscreen mode Exit fullscreen mode

Testing

Run unit tests:

mvn test
Enter fullscreen mode Exit fullscreen mode

(If you add advanced features, you can also include integration tests using profiles or Testcontainers.)


Deployment

You can deploy LogX anywhere Spring Boot apps run:

  • AWS EC2
  • Docker containers
  • DigitalOcean / Render
  • Kubernetes
  • On-prem servers

Example CI/CD pipeline:

  1. Build
  2. Run tests
  3. Package JAR
  4. Build Docker image
  5. Deploy to staging
  6. Promote to production

Extending & Customization

  • Add new endpoints: Create a controller under com.logx.controller
  • Change log format: Update logback-spring.xml
  • Enable JSON logs: Add logstash-logback-encoder and create a JSON appender
  • Integrate tracing: Add OpenTelemetry SDK

Troubleshooting / FAQ

Q: Logs aren’t showing requestId.
A: Ensure the RequestIdFilter is active and MDC pattern is present in logback.

Q: Error responses don't include requestId.
A: Check GlobalExceptionHandler and ErrorResponse model.

Q: My logs folder isn’t created.
A: Make sure your application has write permission and LOG_DIR is set correctly.


License

This project is released under the MIT License.
Use it freely in personal or commercial projects.


About Boileragents

Boileragents creates practical, ready-to-use boilerplates for Spring Boot developers who want to build faster with fewer headaches.
GitHub: https://github.com/boileragents
Email: boileragents@gmail.com


Links & Resources


If Spring Boot LogX saves you time or makes your debugging life easier, please drop a ⭐ on the repo and share your feedback.
Have a feature idea? Email us anytime — we build boilerplates for developers, by developers.

Top comments (0)