Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 355
Christoph Möbius Avatar asked Jul 22 '16 13:07

Christoph Möbius


People also ask

How do I enable logging in spring boot?

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.

How do I create a log file in spring boot project?

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.

Which is the default logging file in Springboot?

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.

Is it mandatory to add spring boot starter logging?

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.


2 Answers

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.

like image 63
Vivek Raja Avatar answered Sep 20 '22 17:09

Vivek Raja


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

like image 30
Christoph Möbius Avatar answered Sep 18 '22 17:09

Christoph Möbius