Log to File in Spring Boot

In this tutorial, you will learn how to configure your Spring Boot application to log messages to a file.

Specify File Path

To make your application log messages to a file, you will need to configure a couple of new properties in the application.properties file.

logging.file.path=/path/to/a/file
logging.file.name=log.txt

You might also need to enable a specific logging level for your application. To do that, add the following configuration property to an application.properties file.

logging.level.<logger>=DEBUG

Where logger is the root package of your Spring Boot application. For example, if the root package of my Spring Boot application is com.appsdeveloperblog then the logging.level configuration will look for me as below.

logging.level.com.appsdeveloperblog=DEBUG

I hope this short tutorial, was helpful for you.

If you are interested in learning more about building RESTful Web Services and Microservices with Spring Boot and Spring Cloud please have a look at my complete video course: Spring Boot Microservices and Spring Cloud.


Leave a Reply

Your email address will not be published. Required fields are marked *

Free Video Lessons

Enter your email and stay on top of things,

Subscribe!