HowToDoInJava

  • Python
  • Java
  • Spring Boot
  • Dark Mode
Home / Spring Boot 2 / Spring boot embedded server logs

Spring boot embedded server logs

Learn to enable and customize the internal and access logs generated for embedded servers in Spring boot e.g. tomcat, jetty & undertow.

1. Types of logging for embedded servers

Generally, in an application we would like to categorize the embedded logs in two categories:

1.1. Access logs

Access logs represent information related to the received request, sent response to the client and important details in between when the request was processed.

1.2. Internal logs

Internal logs give logging information internal to how tomcat server is running inside the box. It’s more of internal information and does not provide much help until we are facing some issue with the server itself.

2. Access logging in embedded servers

Access logs can be configured for Tomcat, Undertow, and Jetty through their respective namespaces in properties file.

For instance, the following settings will enable access logs with a custom pattern [more info].

#tomcat
server.tomcat.basedir=C:/temp/logs
server.tomcat.accesslog.enabled=true
server.tomcat.accesslog.pattern=%t %a "%r" %s (%D ms)

#undertow
server.undertow.accesslog.directory=C:/temp/logs
server.undertow.accesslog.enabled=true
server.undertow.accesslog.pattern=%t %a "%r" %s (%D ms)

#jetty
server.jetty.accesslog.filename=/var/log/jetty-access.log
server.jetty.accesslog.enabled=true

The default location for tomcat logs is a logs directory relative to the Tomcat base directory, which is temp directory. You can provide the location of generated logs in filesystem by overriding basedir property.

We can find all supported properties for embedded server’s access logs in this reference page.

#tomcat

server.tomcat.accesslog.buffered=true # Whether to buffer output such that it is flushed only periodically.
server.tomcat.accesslog.directory=logs # Directory in which log files are created. Can be absolute or relative to the Tomcat base dir.
server.tomcat.accesslog.enabled=false # Enable access log.
server.tomcat.accesslog.file-date-format=.yyyy-MM-dd # Date format to place in the log file name.
server.tomcat.accesslog.pattern=common # Format pattern for access logs.
server.tomcat.accesslog.prefix=access_log # Log file name prefix.
server.tomcat.accesslog.rename-on-rotate=false # Whether to defer inclusion of the date stamp in the file name until rotate time.
server.tomcat.accesslog.request-attributes-enabled=false # Set request attributes for the IP address, Hostname, protocol, and port used for the request.
server.tomcat.accesslog.rotate=true # Whether to enable access log rotation.
server.tomcat.accesslog.suffix=.log # Log file name suffix.

#jetty

server.jetty.accesslog.append=false # Append to log.
server.jetty.accesslog.date-format=dd/MMM/yyyy:HH:mm:ss Z # Timestamp format of the request log.
server.jetty.accesslog.enabled=false # Enable access log.
server.jetty.accesslog.extended-format=false # Enable extended NCSA format.
server.jetty.accesslog.file-date-format= # Date format to place in log file name.
server.jetty.accesslog.filename= # Log filename. If not specified, logs redirect to "System.err".
server.jetty.accesslog.locale= # Locale of the request log.
server.jetty.accesslog.log-cookies=false # Enable logging of the request cookies.
server.jetty.accesslog.log-latency=false # Enable logging of request processing time.
server.jetty.accesslog.log-server=false # Enable logging of the request hostname.
server.jetty.accesslog.retention-period=31 # Number of days before rotated log files are deleted.
server.jetty.accesslog.time-zone=GMT # Timezone of the request log.

#undertow

server.undertow.accesslog.dir= # Undertow access log directory.
server.undertow.accesslog.enabled=false # Whether to enable the access log.
server.undertow.accesslog.pattern=common # Format pattern for access logs.
server.undertow.accesslog.prefix=access_log. # Log file name prefix.
server.undertow.accesslog.rotate=true # Whether to enable access log rotation.
server.undertow.accesslog.suffix=log # Log file name suffix.

3. Internal logs in embedded servers

To generate internal logging for embedded server in spring boot, we need to define logging level for the server component.

#Tomcat

logging.level.org.apache.tomcat=DEBUG
logging.level.org.apache.catalina=DEBUG

#Jetty
logging.level.org.eclipse.jetty=INFO
logging.level.org.eclipse.jetty.websocket=DEBUG

#Undertow

logging.level.io.undertow.server=DEBUG
logging.level.io.undertow.websockets=DEBUG

Drop me your questions related to how to enable and customize the server logs for embedded servers (tomcat, jetty and undertow) in spring boot applications.

Happy Learning !!

Was this post helpful?

Let us know if you liked the post. That’s the only way we can improve.
TwitterFacebookLinkedInRedditPocket

About Lokesh Gupta

A family guy with fun loving nature. Love computers, programming and solving everyday problems. Find me on Facebook and Twitter.

Feedback, Discussion and Comments

  1. John

    May 1, 2020

    Lokesh,

    Thanks for this helpful post. I specified all the properties as you showed here in my application.properties, but nothing was logged by Spring Boot. That might have something to do with the fact that I use log4j and have to use the following exclusion:
    all*.exclude module : ‘spring-boot-starter-logging’
    in my gradle.

    Is there a way to direct jetty access log to log4j?

    Thanks in advance.

    • Lokesh Gupta

      May 1, 2020

      It is hard to say without knowing the full setup/context.

  2. sriram

    November 16, 2019

    Internal tomcat logs are generated in in file specified by logging.file property along with application logs can we change path for tomcat internal logs like it was there for access logs

  3. Gagan

    October 2, 2019

    Without specifying server.tomcat.basedir, how can we find location of log file generated by embedded tomcat server.

    • Lokesh Gupta

      October 4, 2019

      By default logs go in <temp_folder>/logs.

Comments are closed on this article!

Search Tutorials

Spring Boot Logging

  • Spring Boot – Guide to Logging
  • Spring Boot – log4j2.properties
  • Spring Boot – log4j2.xml
  • Spring Boot – application.yml
  • SB – application.properties
  • Spring Boot – Console log
  • Spring Boot – Performance Log
  • Spring Boot – Multiple log files
  • Spring Boot – Embed server logs
  • SB – Active profile logging
  • SB – Logging with Lombok

Spring Boot 2 Tutorial

  • Spring Boot – Introduction
  • Spring Boot – Starter parent
  • Spring Boot – Starter templates
  • Spring Boot – Multi-module project
  • Spring Boot – Annotations
  • Spring Boot – Auto configuration
  • Spring Boot – AOP
  • Spring Boot – Logging
  • Spring Boot – DevTools
  • Spring Boot – WAR Packaging
  • Spring Boot – REST API
  • Spring Boot – CRUD
  • Spring Boot – OAuth2
  • Spring Boot – Testing
  • Spring Boot – RestTemplate
  • Spring Boot – Thymeleaf
  • Spring Boot – Hibernate
  • Spring Boot – DataSource
  • Spring Boot – Error Handling
  • Spring Boot – Caching
  • Spring Boot – Retry
  • Spring Boot – BasicAuth
  • Spring Boot – H2 Database
  • Spring Boot – Ehcache 3.x
  • Spring Boot – Gson
  • Spring Boot – RMI
  • Spring Boot – Send Email
  • Spring Boot – Interview Questions

Spring Boot Tutorial

  • Spring Boot – CommandLineRunner
  • Spring Boot – Configure Jetty
  • Spring Boot – Tomcat Default Port
  • Spring Boot – Context Root
  • Spring Boot – SSL [https]
  • Spring Boot – Get all loaded beans
  • Spring Boot – PropertyEditor
  • Spring Boot – @EnableScheduling
  • Spring Boot – Jersey
  • Spring Boot – SOAP Webservice
  • Spring Boot – SOAP Client
  • Spring Boot – JMSTemplate
  • Spring Boot – REST APIs
  • Spring Boot – JSP View
  • Spring Boot – Actuator endpoints
  • Spring Boot – Role Based Security
  • Spring Boot – RSS / ATOM Feed
  • Spring Boot – Ehcache 2.x

Meta Links

  • About Me
  • Contact Us
  • Privacy policy
  • Advertise
  • Guest and Sponsored Posts

Recommended Reading

  • 10 Life Lessons
  • Secure Hash Algorithms
  • How Web Servers work?
  • How Java I/O Works Internally?
  • Best Way to Learn Java
  • Java Best Practices Guide
  • Microservices Tutorial
  • REST API Tutorial
  • How to Start New Blog

Copyright © 2020 · HowToDoInjava.com · All Rights Reserved. | Sitemap

  • Sealed Classes and Interfaces