V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX 提问指南
azev
V2EX  ›  问与答

关于 SpringBoot 中日志自定义 Logback 配置的问题

  •  
  •   azev · 2020-06-06 18:33:39 +08:00 · 767 次点击
    这是一个创建于 1431 天前的主题,其中的信息可能已经有所发展或是发生改变。

    看 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 发现 后者是无效的
    有没有什么途径让后者覆盖前者?

    fmumu
        1
    fmumu  
       2020-06-06 18:54:53 +08:00 via Android
    在 logback-spring.xml 中使用 spring 配置变量
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2683 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 16:04 · PVG 00:04 · LAX 09:04 · JFK 12:04
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.