Logback 配置文件中 springProfile 指令使用

Logback 日誌模塊在和 Springboot 整合過程中,官網給提供了一些使用建議。
日誌配置文件,官方文檔建議使用-spring 命令格式的配置,日誌框架不直接加載,由SpringBoot解析日誌配置,如:logback-spring.xml。如果直接定義爲logback.xml 將直接被日誌框架識別。

官方文檔地址

一、springProfile 指令介紹

Logback 配置文件中的 springProfile 指令允許您根據配置文件激活參數(active) 選擇性的包含和排查部分配置信息。
springProfile 指令管理的部分配置信息,可以在 configuration 元素內任意地方使用。springProfile 指令使用name 屬性和激活參數(active)關聯。
springProfile 指令可以包含一個配置文件,或者一個文件表達式。

二、配置示例

<springProfile name="test">
    <!-- configuration to be enabled when the "test" profile is active -->
</springProfile>

<springProfile name="dev | test">
    <!-- configuration to be enabled when the "dev" or "test" profiles are active -->
</springProfile>

<springProfile name="!production">
    <!-- configuration to be enabled when the "production" profile is not active -->
</springProfile>

三、配置實例

<springProfile name="prod">
    <root level="info">
        <appender-ref ref="CONSOLE" />
        <appender-ref ref="DEBUG_FILE" />
        <appender-ref ref="INFO_FILE" />
        <appender-ref ref="ERROR_FILE" />
        <appender-ref ref="WARN_FILE" />
    </root>
</springProfile>

四、生效方式

在Java 進程啓動過程中,配置相應的參數即可。

--spring.profiles.active=prod

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章