当前位置:网站首页>logback.xml配置不同级别日志,设置彩色输出
logback.xml配置不同级别日志,设置彩色输出
2022-07-07 14:12:00 【kill-java】
yml或者properties配置文件
logging.config=classpath:logback.xml
resources目录下新建logback.xml文件
<?xml version="1.0" encoding="UTF-8"?>
<!--根标签-->
<configuration>
<!--设置变量,name为变量名,value为值,可以使用${
变量名}方式使用-->
<property name="DIR" value="log"/>
<property name="LOG_HOME" value="/F:/project/logs"/>
<property name="NAME" value="log"/>
<property name="MDC_LOG_PATTERN"
value="%red(%d{yyyy-MM-dd'T'HH:mm:ss.SSS}) %green(%p filesystem %t) %blue(%logger{50}) %yellow([line:%L %msg]%n)"></property>
<!-- 运行日志记录器,日期滚动记录 -->
<appender name="info" class="ch.qos.logback.core.rolling.RollingFileAppender">
<!-- 正在记录的日志文件的路径及文件名 -->
<file>${
LOG_HOME}/${
NAME}/info/${
NAME}.log</file>
<!-- 日志记录器的滚动策略,按日期,按大小记录-->
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<fileNamePattern>${
LOG_HOME}/${
NAME}/info/${
NAME}-%d{
yyyy-MM-dd}.%i.log</fileNamePattern>
<!-- 除按日志记录之外,还配置了日志文件不能超过50M,若超过50M,日志文件会以索引0开始, 命名日志文件,例如bizlog-biz-20181219.0.log -->
<timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
<maxFileSize>50MB</maxFileSize>
<!--保存时间3天-->
<!--<MaxHistory>3</MaxHistory>-->
</timeBasedFileNamingAndTriggeringPolicy>
</rollingPolicy>
<!-- 追加方式记录日志 -->
<append>true</append>
<!-- 日志文件的格式 -->
<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
<pattern>%d{
yyyy/MM/dd' 'HH:mm:ss.SSS} %X{
req.requestId}[line:%L %msg] %n</pattern>
<charset>utf-8</charset>
</encoder>
<!-- 此日志文件只记录info级别的 -->
<filter class="ch.qos.logback.classic.filter.LevelFilter">
<level>info</level>
<onMatch>ACCEPT</onMatch>
<onMismatch>DENY</onMismatch>
</filter>
</appender>
<appender name="error" class="ch.qos.logback.core.rolling.RollingFileAppender">
<!-- 正在记录的日志文件的路径及文件名 -->
<file>${
LOG_HOME}/${
NAME}/error/${
NAME}.log</file>
<!-- 日志记录器的滚动策略,按日期,按大小记录-->
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<fileNamePattern>${
LOG_HOME}/${
NAME}/error/${
NAME}-%d{
yyyy-MM-dd}.%i.log</fileNamePattern>
<!-- 除按日志记录之外,还配置了日志文件不能超过50M,若超过50M,日志文件会以索引0开始, 命名日志文件,例如bizlog-biz-20181219.0.log -->
<timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
<maxFileSize>50MB</maxFileSize>
<!--保存时间3天-->
<!--<MaxHistory>3</MaxHistory>-->
</timeBasedFileNamingAndTriggeringPolicy>
</rollingPolicy>
<!-- 追加方式记录日志 -->
<append>true</append>
<!-- 日志文件的格式 -->
<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
<pattern>%d{
yyyy/MM/dd' 'HH:mm:ss.SSS} %X{
req.requestId}[line:%L %msg] %n</pattern>
<charset>utf-8</charset>
</encoder>
<!-- 此日志文件只记录info级别的 -->
<filter class="ch.qos.logback.classic.filter.LevelFilter">
<level>error</level>
<onMatch>ACCEPT</onMatch>
<onMismatch>DENY</onMismatch>
</filter>
</appender>
<!--ConsoleAppender是打印到控制台的-->
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<!--encoder 默认配置为PatternLayoutEncoder-->
<encoder>
<pattern>${
MDC_LOG_PATTERN}</pattern>
<charset>utf-8</charset>
</encoder>
<!--此日志appender是为开发使用,只配置最底级别,控制台输出的日志级别是大于或等于此级别的日志信息-->
<filter class="ch.qos.logback.classic.filter.ThresholdFilter">
<level>all</level>
</filter>
</appender>
<!--根loger。只有一个level属性,应为已经被命名为"root".-->
<root level="info">
<appender-ref ref="info"/>
<appender-ref ref="STDOUT"/>
<appender-ref ref="error"/>
</root>
</configuration>
边栏推荐
- 分类模型评价标准(performance measure)
- 航運船公司人工智能AI產品成熟化標准化規模應用,全球港航人工智能/集裝箱人工智能領軍者CIMC中集飛瞳,打造國際航運智能化標杆
- Vs tool word highlight with margin
- 2022山东智慧养老展,适老穿戴设备展,养老展,山东老博会
- 121. 买卖股票的最佳时机
- pycharm 终端部启用虚拟环境
- 讲师征集令 | Apache SeaTunnel(Incubating) Meetup 分享嘉宾火热招募中!
- Three. JS introductory learning notes 11:three JS group composite object
- 企业级日志分析系统ELK
- What else can an ordinary person do besides working in a factory to make money?
猜你喜欢

融云斩获 2022 中国信创数字化办公门户卓越产品奖!

Lecturer solicitation order | Apache seatunnel (cultivating) meetup sharing guests are in hot Recruitment!

10 schemes to ensure interface data security

谈谈 SAP iRPA Studio 创建的本地项目的云端部署问题

Xingruige database was shortlisted as the "typical solution for information technology application and innovation in Fujian Province in 2021"

pycharm 终端部启用虚拟环境

Xcode Revoke certificate

torch.numel作用

C4D learning notes 3- animation - animation rendering process case

Dotween -- ease function
随机推荐
SPI master rx time out中断
three.js打造酷炫下雪效果
ThinkPHP URL 路由简介
laravel中将session由文件保存改为数据库保存
AE learning 01: AE complete project summary
修改配置文件后tidb无法启动
Continuous creation depends on it!
Unity3D_ Class fishing project, bullet rebound effect is achieved
Iptables only allows the specified IP address to access the specified port
hellogolang
121. 买卖股票的最佳时机
Particle effect for ugui
Eye of depth (VII) -- Elementary Transformation of matrix (attachment: explanation of some mathematical models)
Odoo集成Plausible埋码监控平台
Application example of infinite list [uigridview]
Numpy --- basic learning notes
PyTorch 中的乘法:mul()、multiply()、matmul()、mm()、mv()、dot()
Leetcode-231-2的幂
招标公告:2022年云南联通gbase数据库维保公开比选项目(第二次)比选公告
Excessive dependence on subsidies, difficult collection of key customers, and how strong is the potential to reach the dream of "the first share of domestic databases"?