当前位置:网站首页>Log4j知识点记录
Log4j知识点记录
2022-04-23 02:39:00 【一只努力xx的程序媛】
看了这个教程,学习到了很多,又经过实践,把教程中没涉及到的点,记录一下,方便以后查看。
https://blog.csdn.net/u013870094/article/details/79518028
log4j.rootLogger=DEBUG,Console,File
#定义日志输出目的地为控制台
log4j.appender.Console=org.apache.log4j.ConsoleAppender
log4j.appender.Console.Target=System.out
#可以灵活地指定日志输出格式,下面一行是指定具体的格式
log4j.appender.Console.layout = org.apache.log4j.PatternLayout
log4j.appender.Console.layout.ConversionPattern=[%p][%l]%m%n
#文件大小到达指定尺寸的时候产生一个新的文件
log4j.appender.File = org.apache.log4j.RollingFileAppender
#指定输出目录
log4j.appender.File.File = logs/dataLog.log
#定义文件最大大小
log4j.appender.File.MaxFileSize = 10MB
# 输出所有日志,如果换成DEBUG表示输出DEBUG以上级别日志
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
第一:
log4j.rootLogger = [ level ] , appenderName1, appenderName2, …
level 是日志记录的优先级,分为OFF、FATAL、ERROR、WARN、INFO、DEBUG、ALL或者您定义的级别。Log4j建议只使用四个级别,优先级从高到低分别是ERROR、WARN、INFO、DEBUG。通过在这里定义的级别,您可以控制到应用程序中相应级别的日志信息的开关。比如在这里定义了INFO级别,则应用程序中所有DEBUG级别的日志信息将不被打印出来。 appenderName就是指日志信息输出到哪个地方,可以同时指定多个输出目的地。
如上面的配置,当log4j.rootLogger=DEBUG,Console…,但是log4j.appender.File.Threshold = INFO ,dataLog.log文件中的日志信息只打印INFO以上级别的,当log4j.appender.File.Threshold = ALL,dataLog.log文件中的日志信息只打印DEBUG以上级别的。
当log4j.rootLogger=INFO,但是log4j.appender.File.Threshold = DEBUG时,dataLog.log文件中的日志信息只打印INFO以上级别的。
总结:当log4j.rootLogger的优先级大于log4j.appender.File.Threshold时,按照log4j.rootLogger为准,否则相反。也就是哪个优先级高使用哪个。
第二:
logger.isDebugEnabled()和logger.isInfoEnabled()的使用场景。
代码中使用logger.info(“参数” + param+ " ,这是一个日志" ),当优先级为INFO以下时才输出,logger.info()内部有判断输出级别的代码。但是在执行logger.info函数之前,后面的表达式已经通过运算拼接成了一个字符串;而如果事先使用 if (logger.isInfoEnabled())进行判断,那么优先级在INFO以上时,就能省去计算字符串操作,在高并发和复杂log信息拼接的情况下,使用这种标准的方法输出log能够省去不小的系统开销。另外,如果构造log信息的过程需要大量字符串操作,建议使用 StringBuilder来完成字符串拼接。
版权声明
本文为[一只努力xx的程序媛]所创,转载请带上原文链接,感谢
https://blog.csdn.net/qq_23888451/article/details/100105831
边栏推荐
- 全局、獨享、局部路由守衛
- 009_ Redis_ Getting started with redistemplate
- 电源电路设计原来是这么回事
- 005_ redis_ Set set
- RT_ Thread ask and answer
- Deploying sbert model based on torchserve < semantic similarity task >
- [unity3d] rolling barrage effect in live broadcasting room
- Leetcode cooking
- 打靶narak
- Execute external SQL script in MySQL workbench and report error
猜你喜欢
![[xjtu Computer Network Security and Management] session 2 Cryptographic Technology](/img/b0/263e8dcbfeb2ce9f504a9c8eb76b07.png)
[xjtu Computer Network Security and Management] session 2 Cryptographic Technology

006_ redis_ Sortedset type

JVM类加载器

They are all intelligent in the whole house. What's the difference between aqara and homekit?

高效音乐格式转换工具Music Converter Pro

After idea is successfully connected to H2 database, there are no sub files
![[untitled]](/img/60/421cda552055664357af47d1a956af.png)
[untitled]

【无标题】
智能辅助功能丰富,思皓X6安全配置曝光:将于4月23日预售

MySQL C language connection
随机推荐
Using go language to build web server
数仓建表111111
Devil cold rice 𞓜 078 devil answers the market in Shanghai and Nanjing; Communication and guidance; Winning the country and killing and screening; The purpose of making money; Change other people's op
[suggestion collection] hematemesis sorting out golang interview dry goods 21 questions - hanging interviewer-1
How to prevent leakage of operation and maintenance data
007_ Redis_ Jedis connection pool
想用Mac学习sql,主要给自己个充足理由买Mac听听意见
解决 注册谷歌邮箱 gmail 手机号无法用于验证
leetcode 烹飪料理
012_ Access denied for user ‘root‘@‘localhost‘ (using password: YES)
Push data from onenet cloud platform to database
The importance of ERP integration to the improvement of the company's system
Day18 -- stack queue
期中汇总(概论+应用层+运输层)
A domestic image segmentation project is heavy and open source!
RT_Thread自问自答
IAR嵌入式開發STM32f103c8t6之點亮LED燈
php+mysql对下拉框搜索的内容修改
005_ redis_ Set set
Niuke hand speed monthly race 48 C (I can't understand the difference. It belongs to yes)