73.1.1 配置logback只输出到文件

如果想禁用控制台日志记录,只将输出写入文件中,你需要一个只导入file-appender.xml而不是console-appender.xml的自定义logback-spring.xml

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <configuration>
  3. <include resource="org/springframework/boot/logging/logback/defaults.xml" />
  4. <property name="LOG_FILE" value="${LOG_FILE:-${LOG_PATH:-${LOG_TEMP:-${java.io.tmpdir:-/tmp}}/}spring.log}"/>
  5. <include resource="org/springframework/boot/logging/logback/file-appender.xml" />
  6. <root level="INFO">
  7. <appender-ref ref="FILE" />
  8. </root>
  9. </configuration>

你还需要将logging.file添加到application.properties

  1. logging.file=myapplication.log