Log Management in Spring Boot

DZone 's Guide to

Log Management in Spring Boot

A tutorial on how to use Spring Boot to log in an output file, and configure where Spring will store your logs.

· DevOps Zone ·
Free Resource

Logging is for sure not a glamorous subject, but it’s a critical one – at least for DevOps and Ops teams. While there are plenty of material on the Web describing how to change your ASCII banner, there is not much on how to efficiently manage the log output.

By default, Spring Boot will output log on the console and not use any file at all.

However, it’s possible to tell Spring Boot to log in an output file. At the simplest level, the path where Spring Boot will put the spring.log file can be easily configured in the application.properties under the logging.path key:


Note that another alternative is to use the logging.file key in order to not only set the file path but also the file name.


While this works very well for development purposes, it’s not an acceptable process for the Ops team to unzip the final jar, update the application.properties file and repackage it — this for each and every different environment.

Spring Boot allows to override the value set in the packaged file (if any) on the command-line as a standard system property when launching the jar:

java -jar -Dlogging.path=/tmp myapp.jar

Finally, it’s also possible to override this value when invoking the Spring Boot Maven plugin on the command line. However, directly using the system property doesn’t work for the plugin will spawn another JVM. One has to use the run.jvmArguments system property and delegate it the wanted value:

mvn spring-boot:run -Drun.jvmArguments="-Dlogging.path=/tmp"

Note that this works for every available property!

devops, devops best practices, logging, spring boot

Published at DZone with permission of Nicolas Frankel . See the original article here.

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}