I use Spring Boot and want it to write log output to a file.
According to the docs, this is simply done by setting
logging.file=filename.log
While the console output works fine, filename.log
is not created. Also, if I create the file manually, nothing is written to it. What do I miss?
You can enable debug logging by specifying --debug when starting the application from the command-line. Spring Boot provides also a nice starting point for logback to configure some defaults, coloring etc. the base. xml file which you can simply include in your logback.
To make Spring Boot write its log to disk, set the path and filename. With this configuration, Spring Boot will write to the console and also to a log file called spring. log , at the path you specify.
By default, Spring Boot will only log to the console and will not write log files. If you want to write log files in addition to the console output you need to set a logging. file or logging. path property (for example in your application.
If we do not provide any logging-specific configuration, we will still see logs printed in “console” because default logging uses Logback to log DEBUG messages into the Console. Spring boot's internal logging is written with Apache Commons Logging so it is one and only mandatory dependency.
Use logging.file.name
instead of logging.file
In higher versions of spring-boot-parent(from version 2.2.0)
, property logging.file is deprecated.
I found a solution. I am not very happy with it since it still does not answer my original question why the logging.file
property is not respected.
I created the logback-spring.xml
from Georges' answer in the same directory where application.properties
resides. According to the documentation Spring Boot will pick it up from there. Apparently, this does not happen in my case.
I need to additionally add logging.config=classpath:logback-spring.xml
in order it is picked up by Spring. The relevant parts of my application.properties
are now
logging.config=classpath:logback-spring.xml logging.file=logs/logfile.log
(I created the logs
directory manually.)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With