当前位置:网站首页>Logback different packages (business logs) are output to different log files
Logback different packages (business logs) are output to different log files
2022-07-18 16:09:00 【Procedural ape (siege lion)】
One of the main purposes of logging is to easily find the cause of the problem when there is a problem , But sometimes too many logs will also cause a lot of disk space , Therefore, appropriate log storage configuration is required .
A feasible method is to target different log types , Configure a separate log storage policy , Include the file name , Rolling strategy and maximum number of logs .
1. Define log output file
<!-- Business log output -->
<appender name="biz_info" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>${log.path}/biz_info.log</file>
<!-- Circular policy : Create log files based on time -->
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<!-- Log file name format -->
<fileNamePattern>${log.path}/biz-info.%d{yyyy-MM-dd}.log</fileNamePattern>
<!-- Maximum log retention 60 individual -->
<maxHistory>60</maxHistory>
<cleanHistoryOnStart>true</cleanHistoryOnStart>
</rollingPolicy>
<encoder>
<pattern>${log.pattern}</pattern>
</encoder>
<filter class="ch.qos.logback.classic.filter.LevelFilter">
<!-- Level of filtering -->
<level>INFO</level>
<!-- Operation when matching : receive ( Record ) -->
<onMatch>ACCEPT</onMatch>
<!-- Operation in case of mismatch : Refuse ( Don't record ) -->
<onMismatch>DENY</onMismatch>
</filter>
</appender>maxHistory: Parameter indicates the maximum number of reserved log files
{yyyy-MM-dd}: The parameter indicates that the file is divided by day ,{yyyy-MM-dd-HH} Indicates that the file is split by hour . Because the string formatted by time is different from the previous string , Then regenerate a file . At this time, the generated file name , There needs to be more -%i
cleanHistoryOnStart: Set to true, It means to clear redundant logs when starting .
<!-- Business log output -->
<appender name="biz_info" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>${log.path}/biz_info.log</file>
<!-- Circular policy : Create log files based on time -->
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<!-- Log file name format -->
<fileNamePattern>${log.path}/biz-info.%d{yyyy-MM-dd}-%i.log</fileNamePattern>
<!-- Maximum log retention 60 individual -->
<maxHistory>60</maxHistory>
<timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
<maxFileSize>100MB</maxFileSize>
</timeBasedFileNamingAndTriggeringPolicy>
</rollingPolicy>
<encoder>
<pattern>${log.pattern}</pattern>
</encoder>
<filter class="ch.qos.logback.classic.filter.LevelFilter">
<!-- Level of filtering -->
<level>INFO</level>
<!-- Operation when matching : receive ( Record ) -->
<onMatch>ACCEPT</onMatch>
<!-- Operation in case of mismatch : Refuse ( Don't record ) -->
<onMismatch>DENY</onMismatch>
</filter>
</appender>timeBasedFileNamingAndTriggeringPolicy: Divide by file size .
2. Definition logger
<!-- Business log -->
<logger name="biz_info" level="info" additivity="false">
<appender-ref ref="biz_info"/>
</logger>additivity="false" Indicates that the log here is not written root Corresponding logger.
3. Definition logger Variable
private static final Logger log = LoggerFactory.getLogger("biz_info");Classes that need logging , Definition logger Variable .
4. Log
log.info(" The list shows ");Just record the log in the normal way .
边栏推荐
- Elaticsearch installs Vietnamese word breaker
- ELK集群部署(七)之ELK集群启动顺序
- 力扣------宝石与石头
- CF609A USB Flash Drives
- "Detective Conan" 1049 words painting collapse, the role of frequent "face changes"
- What are the core technologies of okcc call center system
- JS calculation accuracy and data format
- ELK集群部署(九)之logstash过滤规则
- Elk cluster startup sequence of elk cluster deployment (7)
- Elk cluster deployment (V) deployment filebeat
猜你喜欢

Power buckle ----- gemstones and stones
C语言实训通讯录(静态和动态版本)

Principle analysis of Rex engine of osgearth (one, two, eight) Rex engine and layer projection and their relationship

465-剑指offer(53-I、53-II、04、50)

Graphic array calculation module numpy (trigonometric function, rounding function, converting radian to angle, statistical analysis function, median, array sorting, argsort(), lexport())

Autojs learning - Application List

Deepin wine QQ/微信中文显示为方块的原因之一

为健康增值,为时代赋能|仙乐健康发布年度可持续发展报告

全局变量、局部变量、静态变量和常量的地址分配

图解数组计算模块NumPy下(三角函数、四舍五入函数(around)、取整、将弧度转化为角度、统计分析函数、中位数、数组的排序、argsort()、lexsort())
随机推荐
HCIP - GRE/MGRE、OSPF
NFT players' consensus segmentation: money, community and culture
7.14二分,LCA,差分,思维构造
High resolution network (Part 2): backbone and key detector of mmpose code explanation
Power buckle ----- gemstones and stones
query string、formData和request payload的区别
Deepin wine QQ/微信中文显示为方块的原因之一
What does SPK interface mean
为健康增值,为时代赋能|仙乐健康发布年度可持续发展报告
社交网络的充分去中心化
Renewable finance refi: providing technology and financial system beneficial to the earth
可再生金融ReFi:提供对地球有利的技术和金融系统
bbox center-size representation and corners representation
465-剑指offer(53-I、53-II、04、50)
力扣------宝石与石头
ValueError: The number of FixedLocator locations (7), usually from a call to set_ticks, does not mat
Uniapp code scanning native plug-ins (Google mlkit, zxing; support scanning multiple codes at the same time)
ARTS_ 202207W1
Kubedm install kubernetes 1.15 best practices
How to set up domain name resolution?