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