当前位置:网站首页>Log4j knowledge point record
Log4j knowledge point record
2022-04-23 02:41:00 【An effort to XX program yuan】
Read this tutorial , I learned a lot , After practice , Put the points not covered in the tutorial , Make a note of , Easy to check later .
https://blog.csdn.net/u013870094/article/details/79518028
log4j.rootLogger=DEBUG,Console,File
# Define log output destination as console
log4j.appender.Console=org.apache.log4j.ConsoleAppender
log4j.appender.Console.Target=System.out
# Flexibility to specify log output format , The following line specifies the specific format
log4j.appender.Console.layout = org.apache.log4j.PatternLayout
log4j.appender.Console.layout.ConversionPattern=[%p][%l]%m%n
# A new file is generated when the file size reaches the specified size
log4j.appender.File = org.apache.log4j.RollingFileAppender
# Specify output directory
log4j.appender.File.File = logs/dataLog.log
# Define maximum file size
log4j.appender.File.MaxFileSize = 10MB
# Output all logs , If replaced DEBUG Indicative output DEBUG Above level log
log4j.appender.File.Threshold = INFO
log4j.appender.File.layout = org.apache.log4j.PatternLayout
log4j.appender.File.layout.ConversionPattern =%d{
yyyy-MM-dd HH\:mm\:ss} [%p][%l]%m%n
First of all :
log4j.rootLogger = [ level ] , appenderName1, appenderName2, …
level Is the priority of logging , It is divided into OFF、FATAL、ERROR、WARN、INFO、DEBUG、ALL Or the level you define .Log4j It is recommended to use only four levels , The priorities from high to low are ERROR、WARN、INFO、DEBUG. By the level defined here , You can control the switch to the corresponding level of log information in the application . For example, it defines INFO Level , Then all of the DEBUG Level log information will not be printed out . appenderName It refers to where the log information is output , Multiple output destinations can be specified at the same time .
Like the configuration above , When log4j.rootLogger=DEBUG,Console…, however log4j.appender.File.Threshold = INFO ,dataLog.log The log information in the file only prints INFO Above the level of , When log4j.appender.File.Threshold = ALL,dataLog.log The log information in the file only prints DEBUG Above the level of .
When log4j.rootLogger=INFO, however log4j.appender.File.Threshold = DEBUG when ,dataLog.log The log information in the file only prints INFO Above the level of .
summary : When log4j.rootLogger Is greater than log4j.appender.File.Threshold when , according to log4j.rootLogger Subject to , Otherwise, vice versa . That is, which priority is higher and which .
second :
logger.isDebugEnabled() and logger.isInfoEnabled() Usage scenarios of .
The code uses logger.info(“ Parameters ” + param+ " , This is a log " ), When the priority is INFO Output only when ,logger.info() There is internal code to judge the output level . But in execution logger.info Function before , The following expressions have been spliced into a string through operation ; And if you use it in advance if (logger.isInfoEnabled()) Judge , So the priority is INFO When above , You can eliminate the calculation of string operations , In high concurrency and complexity log In the case of information splicing , Use this standard method to output log It can save a lot of system overhead . in addition , If the structure log The process of information requires a lot of string operations , It is recommended to use StringBuilder To complete string splicing .
版权声明
本文为[An effort to XX program yuan]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204230239165939.html
边栏推荐
- 每日一题冲刺大厂第十六天 NOIP普及组 三国游戏
- Interpretation of the future development of smart agriculture
- So library dependency
- [XJTU计算机网络安全与管理]第二讲 密码技术
- 能做多大的单片机项目程序开发,就代表了你的敲代码的水平
- Rhcsa day 3 operation
- win查看端口占用 命令行
- Halo open source project learning (I): project launch
- Flink stream processing engine system learning (III)
- JSP page nesting
猜你喜欢

一个国产图像分割项目重磅开源!

windows MySQL8 zip安装

Web learning record (medium)

Interpretation of the future development of smart agriculture

Modification du contenu de la recherche dans la boîte déroulante par PHP + MySQL
![[untitled]](/img/60/421cda552055664357af47d1a956af.png)
[untitled]

Implementation of distributed scenario business operation log (based on redis lightweight)
![[wechat applet] set the bottom menu (tabbar) for the applet](/img/e2/98711dfb1350599cbdbdf13508b84f.png)
[wechat applet] set the bottom menu (tabbar) for the applet

Understanding process (multithreading primary)

A domestic image segmentation project is heavy and open source!
随机推荐
1、 Sequence model
解决 注册谷歌邮箱 gmail 手机号无法用于验证
Six very 6 computer driver managers: what software is good for driver upgrade? Recommended by the best computer driver management software abroad
Preliminary understanding of stack and queue
类初始化和实例初始化面试题
MySQL / SQL Server判断表或临时表存在则删除
MySQL JDBC编程
TypeScript(1)
全局、獨享、局部路由守衛
Hack the box optimum
IAR嵌入式開發STM32f103c8t6之點亮LED燈
[xjtu Computer Network Security and Management] session 2 Cryptographic Technology
OCR识别PDF文件
【unity3D】直播间滚动式弹幕效果
win查看端口占用 命令行
MySQL JDBC programming
Suggestion: block reference sorting is in the order of keywords
使用Go语言构建Web服务器
Intelligent agricultural management model
打靶narak