V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
Newyorkcity
V2EX  ›  问与答

我给自己的 springboot 项目写了个 logback.xml,然后 springboot 默认自带的打印也没有了。我只是希望能配置一些我自己的记录器,自带的不想动,该怎么做?

  •  
  •   Newyorkcity · Apr 5, 2020 · 1339 views
    This topic created in 2214 days ago, the information mentioned may be changed or developed.
    谢谢
    Supplement 1  ·  Apr 6, 2020
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE configuration>

    <configuration scan="true">
    <include resource="org/springframework/boot/logging/logback/base.xml"/>
    <logger name="your.application.package" level="DEBUG"/>
    </configuration>
    5 replies    2020-04-06 21:52:43 +08:00
    uxstone
        1
    uxstone  
       Apr 5, 2020   ❤️ 1
    把 spring boot 源码里的那个 logback.xml 拷贝到项目里, 再此基础上做其他的配置修改
    Newyorkcity
        3
    Newyorkcity  
    OP
       Apr 6, 2020
    @aragakiyuii 这个文档我在看 springboot 文档的时候也找到了。。 我试图把

    <property name="CONSOLE_LOG_PATTERN"

    就这个它默认的输出格式给复制过来,然后给我的 appender 套上。。但是很遗憾报错了。。

    能麻烦再说说这个文件要怎么利用么?
    aragakiyuii
        4
    aragakiyuii  
       Apr 6, 2020   ❤️ 1
    @Newyorkcity springboot 格式合起来应该是这样的,他把一些东西放分散到别的 xml 中了,可以看看上层 logback 文件夹中 base.xml 和 console-appender.xml

    ``` xml
    <?xml version="1.0" encoding="UTF-8"?>
    <configuration>
    <conversionRule conversionWord="clr" converterClass="org.springframework.boot.logging.logback.ColorConverter" />
    <conversionRule conversionWord="wex" converterClass="org.springframework.boot.logging.logback.WhitespaceThrowableProxyConverter" />
    <conversionRule conversionWord="wEx" converterClass="org.springframework.boot.logging.logback.ExtendedWhitespaceThrowableProxyConverter" />

    <appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
    <encoder>
    <pattern>${CONSOLE_LOG_PATTERN:-%clr(%d{${LOG_DATEFORMAT_PATTERN:-yyyy-MM-dd HH:mm:ss.SSS}}){faint} %clr(${LOG_LEVEL_PATTERN:-%5p}) %clr(${PID:- }){magenta} %clr(---){faint} %clr([%15.15t]){faint} %clr(%-40.40logger{39}){cyan} %clr(:){faint} %m%n${LOG_EXCEPTION_CONVERSION_WORD:-%wEx}}</pattern>
    </encoder>
    </appender>

    <root level="INFO">
    <appender-ref ref="CONSOLE"/>
    </root>
    </configuration>
    ```
    Newyorkcity
        5
    Newyorkcity  
    OP
       Apr 6, 2020
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE configuration>

    <configuration scan="true">
    <include resource="org/springframework/boot/logging/logback/base.xml"/>
    <logger name="your.application.package" level="DEBUG"/>
    </configuration>
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   1030 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 31ms · UTC 22:29 · PVG 06:29 · LAX 15:29 · JFK 18:29
    ♥ Do have faith in what you're doing.