Spring Boot enable http requests logging access logs
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.
Introduction
In Spring Boot, “access logs” usually mean one log line per HTTP request emitted by the embedded web server. That is different from application logging inside controllers or filters. If all you need is request method, path, status, and timing, enabling the server’s access log is usually the cleanest approach.
Enable Access Logs on the Embedded Server
For the default embedded Tomcat setup, the basic properties look like this:
This turns on Tomcat access logging and writes request lines to the configured directory. The pattern controls what appears in each line, such as:
- client address
- request line
- response status
- response size
- request duration
For many production services, this is enough and has the advantage of keeping request logging at the server layer instead of mixing it into business code.
Know What Access Logs Are Good For
Access logs are ideal for:
- request auditing
- coarse performance monitoring
- status-code analysis
- traffic troubleshooting
They are not the best tool for logging request bodies, controller-specific business fields, or structured application events. For those, use filters, interceptors, or explicit application logging.
Use a Filter for Request-Level Application Logging
If you want more control from inside the Spring application, a filter is a common option. CommonsRequestLoggingFilter is a lightweight starting point:
This is not the same as a Tomcat access log. It runs in the application stack and is better suited to application-aware request logging.
Access Logs Versus Request Bodies
This distinction matters because many developers turn on access logs and then expect to see JSON request bodies. Server access logs normally do not log bodies. That is intentional, because bodies can be large, sensitive, and expensive to capture.
If you genuinely need body logging:
- use an application filter or interceptor
- be careful with privacy and secrets
- consider truncation rules
- avoid logging large payloads blindly
Access logs are for request metadata, not full traffic capture.
Include Correlation Information Deliberately
If your service uses request ids or tracing headers, make sure the access-log pattern or filter strategy includes the right correlation fields. Otherwise you will have request logs that are hard to connect to application logs and distributed traces.
For example, if a reverse proxy injects correlation headers, an application filter may be the easier place to copy those values into the logging context.
Container Choice Still Matters
Spring Boot can run on Tomcat, Jetty, or Undertow, and access-log properties differ by container. The example above is Tomcat-specific. That is one reason it helps to think of access logging as a server feature, not a universal Spring abstraction.
If the app is not using embedded Tomcat, check the matching server settings rather than assuming Tomcat property names will work.
Common Pitfalls
The most common mistake is confusing access logs with application logs. Access logs are generated by the web server and are mostly about request metadata, not domain behavior.
Another pitfall is enabling request-body logging casually. That can expose secrets, increase log volume, and create serious compliance problems if done without limits.
It is also easy to forget that property names are server-specific. A Tomcat example does not automatically apply to Jetty or Undertow.
Finally, request logging without correlation ids is often much less useful than expected. If the logs cannot be connected to the rest of the system, debugging remains slow even though the requests are technically logged.
Summary
- For standard request metadata, enable the embedded server’s access log first.
- On Tomcat, use
server.tomcat.accesslog.*properties. - Access logs are good for path, status, size, and timing, not full request bodies.
- Use filters or interceptors when you need application-aware request logging.
- Be deliberate about privacy, payload size, and correlation ids when designing HTTP request logs.
Related reading
- Spring Boot How to add another WAR files to the embedded tomcat?
- Spring Boot Kafka health indicator
- Spring Boot, logback and logging.config property
- Spring Boot logging pattern
- Spring boot http response compression doesn't work for some User-Agents
- spring boot https PKCS12 DerInputStream.getLength lengthTag111, too big
- Spring Boot enabling CORS by application.properties
- Spring boot errorjava.lang.ArrayStoreException sun.reflect.annotation.TypeNotPresentExceptionProxy

System Design Fundamentals
Build a strong foundation in designing scalable, reliable distributed systems.
View the courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.