How to create log file in Spring Boot
date
Aug 25, 2022
slug
create-log-file-in-spring-boot
status
Published
tags
Tutorial
Log4j
Log
SLF4J
Splunk
Spring Boot
summary
type
Post
Background
I’m using
Log4j
for logging in my Spring Boot
project, and I can see logs show up on console.Now I want to log to a file and add it to
Splunk
to be monitored.Solution
There are two ways to log to a file:
- Create
log4j2.xml
in thesrc/main/resources
folder.
As you can see above I specified that the
ecommerce.log
file to be saved to a logs
folder in the project itself.But you can specify that the log file to be saved to a folder of your computer, Desktop for example, by setting the option:
- Add logging properties in
application.properties
.