https://github.com/bootcamptoprod/spring-boot-ai-logging-demo
A simple Spring Boot app demonstrating three approaches to log Spring AI API requests and responses
https://github.com/bootcamptoprod/spring-boot-ai-logging-demo
spring-ai-custom-interceptor spring-ai-log-request spring-ai-log-response spring-ai-logging spring-ai-request-and-response-logging spring-ai-request-logging spring-ai-response-logging
Last synced: 4 months ago
JSON representation
A simple Spring Boot app demonstrating three approaches to log Spring AI API requests and responses
- Host: GitHub
- URL: https://github.com/bootcamptoprod/spring-boot-ai-logging-demo
- Owner: BootcampToProd
- Created: 2025-04-05T13:22:07.000Z (8 months ago)
- Default Branch: main
- Last Pushed: 2025-04-26T13:35:35.000Z (8 months ago)
- Last Synced: 2025-04-26T14:33:23.940Z (8 months ago)
- Topics: spring-ai-custom-interceptor, spring-ai-log-request, spring-ai-log-response, spring-ai-logging, spring-ai-request-and-response-logging, spring-ai-request-logging, spring-ai-response-logging
- Language: Java
- Homepage: https://bootcamptoprod.com/spring-ai-log-model-requests-and-responses/
- Size: 8.79 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# 🔍 Spring AI Log Model Requests and Responses - 3 Easy Ways
This repository demonstrates **three beginner-friendly approaches** to log requests and responses when using **Spring AI**.
---
## 📌 What are we trying to achieve?
We want to **log both the requests** and the **responses** when making use of Spring AI in a Spring Boot application.
We found **three effective approaches** to make this happen—thanks to:
- [GitHub discussion thread](https://github.com/spring-projects/spring-ai/discussions/450)
- [GitHub issue comment](https://github.com/spring-projects/spring-ai/issues/883#issuecomment-2739772323)
- [Official Spring AI docs on ChatClient logging](https://docs.spring.io/spring-ai/reference/api/chatclient.html#_logging)
---
## 📚 Want a deeper explanation?
We’ve written a **detailed blog** that explains each logging method with code snippets, setup instructions, and FAQs to help you get started:
**đź”— Blog:** [Spring AI Log Model Requests and Responses - 3 Easy Ways](https://bootcamptoprod.com/spring-ai-log-model-requests-and-responses/)
---
## 🛠️ 3 Approaches for Logging Requests & Responses
| Approach | Description | Branch |
|---------|-------------|--------|
| âś… **Custom Interceptor** | Uses `RestClientCustomizer` and a custom interceptor to log request/response details. | [`main`](https://github.com/BootcampToProd/spring-boot-ai-logging-demo/tree/main) |
| 📒 **Logbook Integration** | Leverages [Zalando’s Logbook](https://github.com/zalando/logbook) to log HTTP traffic cleanly. | [`logbook-logging`](https://github.com/BootcampToProd/spring-boot-ai-logging-demo/tree/logbook-logging) |
| 🧩 **SimpleLoggerAdvisor** | Uses Spring AI’s built-in `SimpleLoggerAdvisor` for logging. | [`simple-logger-advisor-logging`](https://github.com/BootcampToProd/spring-boot-ai-logging-demo/tree/simple-logger-advisor-logging) |
> ✨ Choose the branch based on the implementation you'd like to explore.