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

前端 未结 15 1484
一向
一向 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:45

    Here is how i managed to write output to a local file file. To disable console logging and write output only to a file you need a custom logback-spring.xml ( call it logback-spring.xml so you ll take advantage of the templating features (date formatting etc..) provided by Boot) that imports file-appender.xml instead of console-appender.xml. In order to achieve this, you must paste this code below into your logback-spring.xml file.

    
    
        
        
        
        
            
        
     
    

    You also need to add the following to your application.properties:

    logging.file=myapplication.log
    

    Notice that this log file myapplication.log will be generated by springboot.

    This is how my application structure tree looks like:

    If you want to have more fun, you can locate the base.xml in your maven dependencies like this:

提交回复
热议问题