小编Lis*_*bon的帖子

logback-spring。无法从 application.yml 读取属性值

我的 logback-spring.xml 从 application.properties 读取良好,但从 application.yml 读取不正常。在我的项目中,我们被要求仅使用 YAML 格式,因为同一项目中的其他微服务正在使用此格式,因此我无法添加属性文件。请帮助我为什么我的 application.yml 没有在 logback.xml 中读取

我尝试了多种方法并在 stackoverflow 上搜索了类似的问题,但没有问题有正确的答案**。请不要将此标记为重复**。

 <?xml version="1.0" encoding="UTF-8"?>
    <configuration>
        <include resource="org/springframework/boot/logging/logback/defaults.xml"/>
        <include resource="org/springframework/boot/logging/logback/base.xml"/>
        <include resource="org/springframework/boot/logging/logback/console-appender.xml"/>
        <property resource ="application.yml"/>
        <property name="LOGS" value="./logs" />
        <appender name="Console"
            class="ch.qos.logback.core.ConsoleAppender">
            <layout class="ch.qos.logback.classic.PatternLayout">
                <Pattern>
                    %black(%d{ISO8601}) %highlight(%-5level) [%blue(%t)] %yellow(%C{1.}): %msg%n%throwable
                </Pattern>
            </layout>
        </appender>
    
        <appender name="RollingFile"
            class="ch.qos.logback.core.rolling.RollingFileAppender">
            <file>${LOGS}/${spring.application.name}.log</file>
            <encoder
                class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
                <Pattern>%d %p %C{1.} [%t] %m%n</Pattern>
            </encoder>
    
            <rollingPolicy
                class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
                <!-- rollover daily and when the file reaches 10 MegaBytes -->
                <fileNamePattern>${LOGS}/archived/spring-boot-logger-%d{yyyy-MM-dd}.%i.log
                </fileNamePattern>
                <timeBasedFileNamingAndTriggeringPolicy
                    class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
                    <maxFileSize>10MB</maxFileSize>
                </timeBasedFileNamingAndTriggeringPolicy>
            </rollingPolicy>
        </appender> …
Run Code Online (Sandbox Code Playgroud)

logback spring-boot spring-logback

1
推荐指数
1
解决办法
3061
查看次数

标签 统计

logback ×1

spring-boot ×1

spring-logback ×1