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

前端 未结 15 1463
一向
一向 2020-12-14 00:01

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
<         


        
15条回答
  •  温柔的废话
    2020-12-14 00:38

    If you are on Spring Boot then you can directly add following properties in application.properties file to set logging level, customize logging pattern and to store logs in the external file.

    These are different logging levels and its order from minimum << maximum.

    OFF << FATAL << ERROR << WARN << INFO << DEBUG << TRACE << ALL

    # To set logs level as per your need.
    logging.level.org.springframework = debug
    logging.level.tech.hardik = trace
    
    # To store logs to external file
    # Here use strictly forward "/" slash for both Windows, Linux or any other os, otherwise, your logs it won't work.      
    logging.file=D:/spring_app_log_file.log
    
    # To customize logging pattern.
    logging.pattern.file= "%d{yyyy-MM-dd HH:mm:ss} - %msg%n"
    

    Please pass through this link to customize your logs more vividly.

    https://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-logging.html

提交回复
热议问题