看 spring 官方这么说
8.1.1. Configure Logback for File-only Output
If you want to disable console logging and write output only to a file, you need a custom logback-spring.xml that imports file-appender.xml but not console-appender.xml, as shown in the following example:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<include resource="org/springframework/boot/logging/logback/defaults.xml" />
<property name="LOG_FILE" value="${LOG_FILE:-${LOG_PATH:-${LOG_TEMP:-${java.io.tmpdir:-/tmp}}/}spring.log}"/>
<include resource="org/springframework/boot/logging/logback/file-appender.xml" />
<root level="INFO">
<appender-ref ref="FILE" />
</root>
</configuration>
You also need to add logging.file.name to your application.properties, as shown in the following example:
logging.file.name=myapplication.log
=======
有个疑问为什么还需要在 application.properties 中再定义 logging.file.name ? 我测试了下 不设置这个变量没有影响啊
而且更重要的 当我同时设置 property name="LOG_FILE" 与 logging.file.name
发现 后者是无效的
有没有什么途径让后者覆盖前者?
1
fmumu 2020-06-06 18:54:53 +08:00 via Android
在 logback-spring.xml 中使用 spring 配置变量
|