当前位置:网站首页>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
边栏推荐
- 使用Go语言构建Web服务器
- Data warehouse construction table 111111
- How to recognize products from the perspective of Dialectics
- The importance of ERP integration to the improvement of the company's system
- [xjtu Computer Network Security and Management] session 2 Cryptographic Technology
- Water diversion into chengluo Valley p1514
- 一、序列模型-sequence model
- Those years can not do math problems, using pyhon only takes 1 minute?
- Jupyter for local and remote access to ECS
- 全局、獨享、局部路由守衛
猜你喜欢

全局、獨享、局部路由守衛

Renesas electronic MCU RT thread development and Design Competition
![[XJTU computer network security and management] Lecture 2 password technology](/img/b0/263e8dcbfeb2ce9f504a9c8eb76b07.png)
[XJTU computer network security and management] Lecture 2 password technology

Rhcsa day 1 operation

1215_ Hello world used by scons

Using go language to build web server

认识进程(多线程_初阶)

How to prevent leakage of operation and maintenance data

Six very 6 computer driver managers: what software is good for driver upgrade? Recommended by the best computer driver management software abroad
![[xjtu Computer Network Security and Management] session 2 Cryptographic Technology](/img/b0/263e8dcbfeb2ce9f504a9c8eb76b07.png)
[xjtu Computer Network Security and Management] session 2 Cryptographic Technology
随机推荐
使用Go语言构建Web服务器
MySQL复杂查询使用临时表/with as(类似表变量)
5W of knowledge points
windows MySQL8 zip安装
Interim summary (Introduction + application layer + transportation layer)
Day 4 of learning rhcsa
The usage and difference of * and & in C language and the meaning of keywords static and volatile
Store consumption SMS notification template
Solve the problem that the registered Google email Gmail mobile number cannot be used for verification
A domestic image segmentation project is heavy and open source!
字符串去掉空格问题
学习正则表达式选项、断言
Water diversion into chengluo Valley p1514
Handwritten memory pool and principle code analysis [C language]
So library dependency
C # import details
Hack the box optimum
[untitled]
WordPress calls the specified page content. 2 get_ children()
leetcode 烹饪料理