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?

Join 7000+ Fellow Programmers

Subscribe to get new post notifications, industry updates, best practices, and much more. Directly into your inbox, for free.

5 thoughts on “Spring boot embedded server logs”

  1. 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.

  2. 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. Without specifying server.tomcat.basedir, how can we find location of log file generated by embedded tomcat server.

Comments are closed.

HowToDoInJava

A blog about Java and its related technologies, the best practices, algorithms, interview questions, scripting languages, and Python.