Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

why doesn't spring-boot listen to the logging.path variable?

Using spring-boot 1.2.3.RELEASE.

The only way I can get spring-boot to log to a specific directory is by setting the "log.file" property like so:

logging.file=/var/log/app.log

But as far as I can tell, according to the docs, I should be doing:

logging.file=app.log
logging.path=/var/log

But it just doesn't seem to listen to the logging.path property, it will just write the file to the current directory.

Are the docs wrong or is there something really obvious I'm missing here?

Also, with this setting, it's still going to do log rolling properly, right?

like image 878
Shorn Avatar asked Apr 21 '15 06:04

Shorn


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.

Can you control logging with spring boot How?

Spring Boot uses Apache Commons logging for all internal logging. Spring Boot's default configurations provides a support for the use of Java Util Logging, Log4j2, and Logback. Using these, we can configure the console logging as well as file logging.

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.

Which logging framework is best for spring boot?

Spring Boot's default logging framework is Logback. Your application code should interface only with the SLF4J facade so that it's easy to switch to an alternative framework if necessary. Log4j2 is newer and claims to improve on the performance of Logback.


3 Answers

From the documentation:

If you want to write log files in addition to the console output you need to set a logging.file or logging.path property

Spring boot considers either file or path property, not both.

This page has all combinations of file and path properties.

like image 121
Mithun Avatar answered Oct 08 '22 02:10

Mithun


Variables path and file can be used simultaneously in the following ways (application.yml):

logging:   path: /var/log/   file: ${logging.path}app.log 

As a result, spring-boot will keep a log in the file /var/log/app.log

like image 41
ZoomAll Avatar answered Oct 08 '22 01:10

ZoomAll


using spring 2.4.5

this is work

logging.file.path=./log/
logging.file.name=${logging.file.path}mylog.txt

or

logging.file.name=./log2/mylog.txt

in summary

logging.file.path=.             # write logs to the current directory
logging.file.path=/home/logs    # write logs to /home/logs
logging.file.path=/mnt/logdir   # write logs to /mnt/logdir

for Spring Boot 1.x : set logging.path

like image 36
afshar Avatar answered Oct 08 '22 01:10

afshar