当前位置:网站首页>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>
边栏推荐
- Unity的三种单例模式(饿汉,懒汉,MonoBehaviour)
- Numpy -- data cleaning
- Leetcode-231-2的幂
- 修改配置文件后tidb无法启动
- Laravel constructor and middleware execution order
- PHP实现微信小程序人脸识别刷脸登录功能
- Asyncio concept and usage
- Unity drawing plug-in = = [support the update of the original atlas]
- PyTorch 中的乘法:mul()、multiply()、matmul()、mm()、mv()、dot()
- How to determine whether the checkbox in JS is selected
猜你喜欢
Mysql database basic operation DQL basic query
星瑞格数据库入围“2021年度福建省信息技术应用创新典型解决方案”
Application example of infinite list [uigridview]
Unity3d click events added to 3D objects in the scene
Balanced binary tree (AVL)
Lecturer solicitation order | Apache seatunnel (cultivating) meetup sharing guests are in hot Recruitment!
torch.numel作用
Odoo集成Plausible埋码监控平台
Three. JS introductory learning notes 10:three JS grid
PyTorch 中的乘法:mul()、multiply()、matmul()、mm()、mv()、dot()
随机推荐
Dotween -- ease function
Use moviepy Editor clips videos and intercepts video clips in batches
PHP实现执行定时任务的几种思路详解
修改配置文件后tidb无法启动
leetcode 241. Different Ways to Add Parentheses 为运算表达式设计优先级(中等)
分步式監控平臺zabbix
Three. JS introductory learning notes 13: animation learning
Good news! Kelan sundb database and Hongshu technology privacy data protection management software complete compatibility adaptation
Aerospace Hongtu information won the bid for the database system research and development project of a unit in Urumqi
Three. JS introductory learning notes 18: how to export JSON files with Blender
ThinkPHP URL 路由简介
Multiplication in pytorch: mul (), multiply (), matmul (), mm (), MV (), dot ()
讲师征集令 | Apache SeaTunnel(Incubating) Meetup 分享嘉宾火热招募中!
Unity3D_ Class fishing project, bullet rebound effect is achieved
Laravel constructor and middleware execution order
C4D learning notes 1- animation - animation key frames
You Yuxi, coming!
Lecturer solicitation order | Apache seatunnel (cultivating) meetup sharing guests are in hot Recruitment!
PHP中exit,exit(0),exit(1),exit(‘0’),exit(‘1’),die,return的区别
Regular expression string