当前位置:网站首页>logback appender简介说明
logback appender简介说明
2022-07-29 06:58:00 【qq_25073223】
转自:
下文笔者讲述logback的appender的简介说明,如下所示:
logback中appender是负责写日志的组件 appender的功能:用于设置日志输出的目的地 日志输出的位置可为控制台、文件、远程套接字服务器、MySQL和其他数据库、JMS和远程UNIX Syslog守护进程等
appender类型
ConsoleAppender:把日志打印到控制台 FileAppender:把日志输出到文件 RollingFileAppender:滚动记录地把日志输出到文件,也就是可以支持日志文件按文件大小拆分或按日期拆分
例
<appender name="infoAppender" class="ch.qos.logback.core.rolling.RollingFileAppender"> <!-- 文件路径 --> <file>${log.filePath}/info.log</file> <!-- 滚动策略 --> <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"> <!-- 设置文件名称 --> <fileNamePattern> ${log.filePath}/info/info.%d{yyyy-MM-dd}.log.gz </fileNamePattern> <!-- 设置最大保存周期 --> <MaxHistory>${log.maxHistory}</MaxHistory> </rollingPolicy> <encoder> <pattern>${log.pattern}</pattern> </encoder> <!-- 过滤器,过滤掉不是指定日志水平的日志 --> <filter class="ch.qos.logback.classic.filter.LevelFilter"> <!-- 设置日志级别 --> <level>INFO</level> <!-- 如果跟该日志水平相匹配,则接受 --> <onMatch>ACCEPT</onMatch> <!-- 如果跟该日志水平不匹配,则过滤掉 --> <onMismatch>DENY</onMismatch> </filter> </appender>
logback子节点
filter过滤器
LevelFilter:级别过滤器,根据日志级别进行过滤。如果日志级别等于配置级别,过滤器会根据onMath 和 onMismatch接收或拒绝日志 ThresholdFilter:临界值过滤器,过滤掉低于指定临界值的日志。当日志级别等于或高于临界值时,过滤器返回NEUTRAL;当日志级别低于临界值时,日志会被拒绝 EvaluatorFilter:求值过滤器,评估、鉴别日志是否符合指定条件
rollingPolicy
用于设置日志的滚动策略
当达到条件后会自动将条件前的日志生成一个备份日志文件
条件后的日志输出到最新的日志文件中
常用的是按照时间来滚动(使用的类TimeBaseRollingPolicy)
还有一种就是基于索引来实现(使用的类FixedWindowRollingPolicy)
fileNamePattern属性设置滚动生成文件的格式,这里设置的精确到天,也就是按照天滚动,如果时间设置精确到秒,就按秒来滚动
maxHistory属性设定最大的文件数,比如按天滚动,这里设置了30天,在第31天日志生成的时候,第一天的日志就会被删掉
triggeringPolicy
日志触发器策略,用于设置日志的大小的控制
当日志达到对应的大小的时候,就会触发
生成新的日志文件。日志大小的控制配合rollingPlicy使用的时候,不同的rollingPolicy会有所不同
encoder
encoder属性的功能用于将事件转换成字节数组并把字节数组写到合适的输出流
encoder可以指定属性值class,这里对应的类只有一个PatternLayoutEncoder,也是默认值,可以不去指定
边栏推荐
- Win11 system error: code execution cannot continue because ierutil.dll cannot be found. Reinstalling the program may fix this problem
- 如何与斯堪尼亚SCANIA建立EDI连接?
- 我的个人网站不让接入微信登录,于是我做了这个
- Docker最新超详细教程——Docker创建运行MySQL并挂载
- 彻底搞懂kubernetes调度框架与插件
- 请问flink支持sqlServer数据库么?获取sqlServer数据库的变化
- 利用C语言巧妙实现棋类游戏——三子棋
- Ethernet interface introduction
- 用户列表 圆形头像并跟随小板块
- Job 7.28 file IO and standard IO
猜你喜欢
最新百亿量化私募名单
Win11 system error: code execution cannot continue because ierutil.dll cannot be found. Reinstalling the program may fix this problem
Explanation of suffix automata (SAM) + Luogu p3804 [template] suffix automata (SAM)
After 4 years of development and 13K, if you want to change to automated testing, can your salary still rise···
Redis基础篇
Excel file reading and writing (creation and parsing)
WPF简单登录页面的完成案例
js第四天流程控制(if语句和switch语句)
Student achievement ranking system based on C language design
SpingBoot整合Quartz框架实现动态定时任务(支持实时增删改查任务)
随机推荐
路由中的生命周期钩子 - activated与deactivated
logback简介及引入方法
npm install报错npm ERR Could not resolve dependency npm ERR peer
After 4 years of development and 13K, if you want to change to automated testing, can your salary still rise···
Interface test actual project 03: execute test cases
2022-07-28:以下go语言代码输出什么?A:AA;B:AB;C:BA;D:BB。 package main import ( “fmt“ ) func main() { f
反射reflect
请问flink支持sqlServer数据库么?获取sqlServer数据库的变化
Error 1045 (28000) access denied for user 'root' @ 'localhost' solution
MySQL如何把行转换为列?
我,28岁,测试员,10月无情被辞:想给还在学测试 的人提个醒......
Unity发送Post请求给GoLang服务端解析并返回
Spingboot integrates the quartz framework to realize dynamic scheduled tasks (support real-time addition, deletion, modification and query tasks)
Homebrew brew update doesn't respond for a long time (or stuck in updating homebrew...)
gcc/g++的使用
以太网接口介绍
2022-07-28: what is the output of the following go language code? A:AA; B:AB; C:BA; D:BB。 package main import ( “fmt“ ) func main() { f
Gin template
Excel file reading and writing (creation and parsing)
MySQL advanced (Advanced) SQL statement (I)