spring-boot default log location

109,360

Solution 1

Spring Boot uses Commons Logging for all internal logging, but leaves the underlying log implementation open.

Default configurations are provided for Java Util Logging, Log4J, Log4J2 and Logback. In each case loggers are pre-configured to use console output with optional file output also available.

From the Spring Boot logging documentation.

The default log configuration will echo messages to the console as they are written. So until you explicitly specify a file as you described, it stays in the Console.

Solution 2

By default Spring Boot does not output logs to any file. If you want to have logs written in a file (in addition to the console output) then you should use either of logging.file or logging.path properties (not both).

In application.properties, just set:

logging.file=/home/ubuntu/spring-boot-app.log

This will create a spring-boot-app.log file under /home/ubuntu.

Solution 3

By default, Spring Boot logs only to the console and does 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.properties).

Below codes in your application.properties will write the log into /home/user/my.log:

logging.path = /home/user
logging.file = my.log
Share:
109,360
cahen
Author by

cahen

Updated on March 27, 2020

Comments

  • cahen
    cahen over 4 years

    In a spring-boot application I can specify a custom log file with

    java -jar spring-boot-app.jar --logging.file=/home/ubuntu/spring-boot-app.log

    But if I don't specify one, where does it go?

    I couldn't find it in any of the following folders:

    /tmp/
    /var/log/
    ~/
    

    I do not have spring-boot-starter-logging or any additional logging dependencies.

    I was hoping to have something similar to catalina.out since the default configuration runs an embedded Tomcat:

    INFO 10374 --- [main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat initialized with port(s): 8100 (http)
    
  • nicobo
    nicobo about 5 years
    only if the current directory is /home/user (see above answers)
  • Paresh
    Paresh about 5 years
    By looking at logs, we can specify one log file, is there a way to specify log file and error file by log level?
  • Rich Tillis
    Rich Tillis about 3 years
    logging.file is now deprecated. Use logging.file.name instead
  • Saurabh Gupta
    Saurabh Gupta about 2 years
    You can only add one property at a time. If you add logging.file then logging.path is ignored. So if you want specific path just use logging.path and leave out logging.file. If you want to rename the logging file then use format in file like /home/user/my.log (I haven't tried it, but it should work). Also link to documentation to verify my claim docs.spring.io/spring-boot/docs/2.1.13.RELEASE/reference/htm‌​l/… . I personally did all this in yml format like below logging: path: /var/service_name