当前位置:网站首页>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>
边栏推荐
- JS 模块化
- 喜讯!科蓝SUNDB数据库与鸿数科技隐私数据保护管理软件完成兼容性适配
- The differences between exit, exit (0), exit (1), exit ('0 '), exit ('1'), die and return in PHP
- 47_ Contour lookup in opencv cv:: findcontours()
- 121. 买卖股票的最佳时机
- [excelexport], Excel to Lua, JSON, XML development tool
- Xcode Revoke certificate
- Three. JS introductory learning notes 08:orbitcontrols JS plug-in - mouse control model rotation, zoom in, zoom out, translation, etc
- prometheus api删除某个指定job的所有数据
- Vs tool word highlight with margin
猜你喜欢
PyTorch 中的乘法:mul()、multiply()、matmul()、mm()、mv()、dot()
Strengthen real-time data management, and the British software helps the security construction of the medical insurance platform
山东老博会,2022中国智慧养老展会,智能化养老、适老科技展
Dotween -- ease function
Application example of infinite list [uigridview]
2022第四届中国(济南)国际智慧养老产业展览会,山东老博会
torch. Numel action
深度之眼(七)——矩阵的初等变换(附:数模一些模型的解释)
Step by step monitoring platform ZABBIX
Mysql database basic operation DQL basic query
随机推荐
Continuous creation depends on it!
MySQL数据库基本操作-DQL-基本查询
神经网络c语言中的指针是怎么回事
Unity3d click events added to 3D objects in the scene
PHP中exit,exit(0),exit(1),exit(‘0’),exit(‘1’),die,return的区别
修改配置文件后tidb无法启动
95.(cesium篇)cesium动态单体化-3D建筑物(楼栋)
Enterprise log analysis system elk
What else can an ordinary person do besides working in a factory to make money?
leetcode 241. Different Ways to Add Parentheses 为运算表达式设计优先级(中等)
模仿企业微信会议室选择
thinkphp3.2.3中设置路由,优化url
Three. JS introductory learning notes 07: external model import -c4d to JSON file for web pages -fbx import
Xcode Revoke certificate
Leetcode-136- number that appears only once (solve with XOR)
Talk about the cloud deployment of local projects created by SAP IRPA studio
Bidding announcement: Fujian Rural Credit Union database audit system procurement project (re bidding)
Eye of depth (VI) -- inverse of matrix (attachment: some ideas of logistic model)
AE learning 01: AE complete project summary
SPI master rx time out中断