如何为配置中尚未存在的任何 spring 配置文件指定默认 Logback 配置

How to specify default Logback configuration for any spring profile that is not already present in the config

这是我简化的 logback-spring.xml 配置:

<configuration>

    <!-- appender config -->

    <springProfile name=dev>
        <!-- dev specific config here -->
    </springProfile>

    <springProfile name=prod>
        <!-- prod specific config here -->
    </springProfile>

    <!-- other profiles -->

</configuration>

当我 运行 我的应用程序具有一些不同的配置文件时,我想获得一些默认的 logback 配置。我在 logback-spring.xml.

中找不到有关某些默认配置的信息

请注意,定义了 2 个以上的配置文件,我不知道其他临时配置文件的名称。

谢谢, 帕夫洛

你可以这样定义它:

<configuration>

<!-- appender config -->

<springProfile name=dev>
    <!-- dev specific config here -->
</springProfile>

<springProfile name=prod>
    <!-- prod specific config here -->
</springProfile>

<!-- other profiles -->

<springProfile name="!(dev| prod)">
   <!-- other specific config here -->
</springProfile>

实际上,发现在 profile 标签之外定义配置就可以了:

<configuration>

    <!-- appenders and profiles -->

    <root level="level here">
        <appender-ref ref="name here"/>
    </root>

    <logger name="name here" level="level here"/>
    <!-- other loggers -->

</configuration>

在这种情况下,它将被视为基本配置。您可以在配置文件特定块中覆盖 appender-ref 和记录器。