Spring Boot logback springProfile区分部署环境
logback Spring Boot 大约 2484 字springProfile
读取spring.profiles.active
设置的值,设置不同环境的不同逻辑。
固定值
dev
:当spring.profiles.active
是dev
时生效。
<springProfile name="dev">
<appender-ref ref="CONSOLE"/>
</springProfile>
| 或
|
:当spring.profiles.active
是dev
或test
时生效。
<springProfile name="dev | test">
<appender-ref ref="CONSOLE"/>
</springProfile>
! 非
!
:当spring.profiles.active
不是prod
时生效。
<springProfile name="!prod">
<appender-ref ref="CONSOLE"/>
</springProfile>
示例
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<include resource="org/springframework/boot/logging/logback/defaults.xml"/>
<include resource="org/springframework/boot/logging/logback/console-appender.xml"/>
<springProperty scope="context" name="logPath" source="log.path" defaultValue="${user.dir}/logs"/>
<appender name="FILE_APPENDER" class="ch.qos.logback.core.rolling.RollingFileAppender">
<File>${logPath}/log-info.log</File>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<FileNamePattern>${logPath}/history-log-%d{yyyy-MM-dd}.zip</FileNamePattern>
<maxHistory>5</maxHistory>
</rollingPolicy>
<encoder>
<Pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{35} - %msg %n</Pattern>
</encoder>
</appender>
<appender name="FILE_APPENDER_ASYNC" class="ch.qos.logback.classic.AsyncAppender">
<discardingThreshold>0</discardingThreshold>
<queueSize>12000</queueSize>
<neverBlock>true</neverBlock>
<appender-ref ref="FILE_APPENDER"/>
</appender>
<root level="INFO">
<appender-ref ref="FILE_APPENDER_ASYNC"/>
<springProfile name="!prod">
<appender-ref ref="CONSOLE"/>
</springProfile>
</root>
<logger name="com.example" level="INFO"/>
</configuration>
备注
Spring Boot
工程中建议将logback
文件命名为logback-spring.xml
。
When possible, we recommend that you use the -spring variants for your logging configuration (for example, logback-spring.xml rather than logback.xml). If you use standard configuration locations, Spring cannot completely control log initialization.
阅读 306 · 发布于 2020-12-25
————        END        ————
扫描下方二维码关注公众号和小程序↓↓↓

昵称:
随便看看
换一批
-
Mac通过ssh连接远程服务器阅读 1161
-
Nginx upstream timed out 10060阅读 285
-
软考-系统架构设计师:关系代数阅读 425
-
PowerShell 快捷键阅读 154
-
数据结构阅读 492
-
Linux uniq命令简单使用阅读 1508
-
设计模式之建造者模式阅读 372
-
MySQL中的覆盖索引阅读 57
-
curl命令遇到重定向时请求重定向后地址阅读 276
-
PostgreSQL使用\copy命令时报character with byte sequence 0xc3 0xa5 in encoding "UTF8" has no equivalent in encoding "GBK"阅读 3496