Home > Spring > Spring Boot > Enable the access logs in Spring Boot for embedded tomcat server

Enable the access logs in Spring Boot for embedded tomcat server

Access logs contains the information about the request received and response sent to the client. It contains all the important data which are required to analyze the type of request coming to the application.

Below are the steps which is required to configure the tomcat access logs for the Spring Boot application.

Settings in application.properties file

# Base directory of the access log.
base.path.log=/log

# Enable access log.
server.tomcat.accesslog.enabled=true 

# Format pattern for access logs.
server.tomcat.accesslog.pattern=%t %a "%r" %s (%D ms) "%{User-Agent}i" "app-vr-@project.version@" 

# Whether to buffer output such that it is flushed only periodically.
server.tomcat.accesslog.buffered=true 

# Directory in which log files are created. Can be absolute or relative to the Tomcat base dir.
server.tomcat.accesslog.directory=/${base.path.log}/app-name

# Date format to place in the log file name.
server.tomcat.accesslog.file-date-format=.yyyy-MM-dd

# Log file name prefix.
server.tomcat.accesslog.prefix=access_log

# Whether to enable access log rotation.
server.tomcat.accesslog.rotate=true

# Whether to defer inclusion of the date stamp in the file name until rotate time.
server.tomcat.accesslog.rename-on-rotate=true

# Log file name suffix.
server.tomcat.accesslog.suffix=.log

These are the common properties files settings which will enable the access log feature in your spring boot application with all set of relevant information.

You can find all supported properties for embedded server’s access logs in this official spring doc reference page.