当前位置:网站首页>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>
边栏推荐
- Leetcode-136- number that appears only once (solve with XOR)
- Mysql database backup script
- 应用程序和matlab的通信方式
- Iptables only allows the specified IP address to access the specified port
- AE learning 02: timeline
- Three. JS introductory learning notes 08:orbitcontrols JS plug-in - mouse control model rotation, zoom in, zoom out, translation, etc
- 【知识小结】PHP使用svn笔记总结
- Laravel 中config的用法
- Lecturer solicitation order | Apache seatunnel (cultivating) meetup sharing guests are in hot Recruitment!
- [hcsd celebrity live broadcast] teach the interview tips of big companies in person - brief notes
猜你喜欢

Numpy -- epidemic data analysis case

What about the pointer in neural network C language

Unity3D_ Class fishing project, control the distance between collision walls to adapt to different models

Leetcode-231-2的幂

Strengthen real-time data management, and the British software helps the security construction of the medical insurance platform

【花雕体验】15 尝试搭建Beetle ESP32 C3之Arduino开发环境

Three. JS introductory learning notes 07: external model import -c4d to JSON file for web pages -fbx import

SysOM 案例解析:消失的内存都去哪了 !| 龙蜥技术

企业级日志分析系统ELK

Xcode Revoke certificate
随机推荐
Apache Doris just "graduated": why should we pay attention to this kind of SQL data warehouse?
Unity3d click events added to 3D objects in the scene
A link opens the applet code. After compilation, it is easy to understand
Numpy -- epidemic data analysis case
Mysql database basic operation DQL basic query
Odoo integrated plausible embedded code monitoring platform
Rongyun won the 2022 China Xinchuang digital office portal excellence product award!
深度之眼(七)——矩阵的初等变换(附:数模一些模型的解释)
谈谈 SAP iRPA Studio 创建的本地项目的云端部署问题
Shader basic UV operations, translation, rotation, scaling
Three singleton modes of unity (hungry man, lazy man, monobehavior)
TCP framework___ Unity
leetcode 241. Different ways to add parentheses design priority for operational expressions (medium)
Common training data set formats for target tracking
分步式監控平臺zabbix
Plate - forme de surveillance par étapes zabbix
iptables只允许指定ip地址访问指定端口
Shipping companies' AI products are mature, standardized and applied on a large scale. CIMC, the global leader in port and shipping AI / container AI, has built a benchmark for international shipping
Three. Introduction to JS learning notes 17: mouse control of 3D model rotation of JSON file
SPI master rx time out中断