springspring-bootlogbackslf4j

Spring Boot - no log file written (logging.file is not respected)


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?


Solution

  • 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.)