简体   繁体   English

带有springProfile的Logback-spring.xml不能与多个配置文件一起使用

[英]Logback-spring.xml with springProfile not working with multiple profiles

I am having multiple profiles in spring boot app and trying to use 3 different appenders.我在 spring 启动应用程序中有多个配置文件并尝试使用 3 个不同的附加程序。

  1. CONSOLE appender控制台附加程序
  2. CONSOLE-GVA appender CONSOLE-GVA 附加器
  3. FILE appender文件附加器

when I am running this with "local" profile to test, then it uses "file" and "console" appender both.当我使用“本地”配置文件运行它进行测试时,它同时使用“文件”和“控制台”附加程序。 I am expecting it should use the only File appender我期望它应该使用唯一的 File appender

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<include resource="org/springframework/boot/logging/logback/defaults.xml"/>
<include resource="org/springframework/boot/logging/logback/file-appender.xml"/>
<include resource="org/springframework/boot/logging/logback/console-appender.xml"/>

<springProperty scope="context" name="maskedProperty" source="gva.logs.masked.property"/>

<springProfile name="!vsi, gva-gaia, !local">

    <appender name="CONSOLE-GVA" class="ch.qos.logback.core.ConsoleAppender">
        <encoder class="ch.qos.logback.core.encoder.LayoutWrappingEncoder">
            <layout class="com.batch.logger.MaskingPatternLayout">
                <pattern>${CONSOLE_LOG_PATTERN}</pattern>
                <patternsProperty>${maskedProperty}</patternsProperty>
            </layout>
        </encoder>
    </appender>

    <root level="INFO">
        <appender-ref ref="CONSOLE-GVA"/>
    </root>
</springProfile>

<springProfile name="!vsi,!gva-gaia,!local">
    <root level="INFO">
        <appender-ref ref="CONSOLE"/>
    </root>
</springProfile>

<springProfile name="vsi,local">

    <appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
        <file>${LOG_PATH}/${LOG_FILE}</file>
        <encoder class="ch.qos.logback.core.encoder.LayoutWrappingEncoder">
            <layout class="com.batch.logger.MaskingPatternLayout">
                <pattern>${FILE_LOG_PATTERN}</pattern>
                <patternsProperty>${maskedProperty}</patternsProperty>
            </layout>
        </encoder>

        <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
            <fileNamePattern>${LOG_PATH}/batch.%d{yyyy-MM-dd}.log</fileNamePattern>
            <maxHistory>14</maxHistory>
        </rollingPolicy>
    </appender>

    <root level="INFO">
        <appender-ref ref="FILE"/>
    </root>
</springProfile>

If the profileNames list size is larger than 1,As long as there is a match means success.如果profileNames列表大小大于1,只要有匹配就表示成功。 local dev matches.vsi.本地开发 match.vsi。 org.springframework.boot.logging.logback,SpringProfileAction#acceptsProfiles(InterpretationContext ic, Attributes attributes) org.springframework.boot.logging.logback,SpringProfileAction#acceptsProfiles(InterpretationContext ic, Attributes 属性)

<springProfile name="!local">
    <root level="INFO">
        <appender-ref ref="CONSOLE"/>
    </root>
</springProfile>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 SpringBoot logback-spring.xml springprofile不起作用 - SpringBoot logback-spring.xml springprofile is not working logback-spring.xml 配置springProfile时创建多个日志文件 - Logback-spring.xml creating multiple log files when configured with springProfile spring boot logback-spring.xml maxFileSize 不适用于 SizeAndTimeBasedRollingPolicy - spring boot logback-spring.xml maxFileSize not working with SizeAndTimeBasedRollingPolicy Spring Boot 忽略 logback-spring.xml - Spring Boot ignoring logback-spring.xml 以编程方式外部化logback-spring.xml - Externalize logback-spring.xml programmatically 无法将config文件夹中logback-spring.xml的属性覆盖到其他模块的logback-spring.xml - Cannot override properties of logback-spring.xml in config folder to other module's logback-spring.xml logback-spring.xml 级别配置中的“java.lang.IllegalStateException:无法从类路径初始化 Logback 日志记录:logback-spring.xml” - "java.lang.IllegalStateException: Could not initialize Logback logging from classpath:logback-spring.xml" in logback-spring.xml level configuration spring 引导命令行运行不使用 logback-spring.xml - spring boot command line run not using logback-spring.xml Spring boot 不加载 logback-spring.xml - Spring boot does not load logback-spring.xml 在Springboot中无法读取logback-spring.xml中的属性 - Unable to read properties in logback-spring.xml in Springboot
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM