当前位置:网站首页>Loggerfactory uses log4j Parameter introduction of properties
Loggerfactory uses log4j Parameter introduction of properties
2022-06-28 08:51:00 【KeepYoung6913】
LoggerFactory Use with log4j.properties Parameter introduction of
One 、LoggerFactory Use
Use org.slf4j To control the output of the log , It is common to use this code
private static final Logger logger = LoggerFactory.getLogger(LoggerFactoryDemo.class);
The dependencies needed are
<!-- slf4j Dependency package 2021.08.19 -->
<!-- https://mvnrepository.com/artifact/org.slf4j/slf4j-log4j12 -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.7.21</version>
</dependency>
<!-- https://mvnrepository.com/artifact/log4j/log4j -->
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
</dependency>
If you encounter the following hot spots
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
So it could be slf4j-log4j12 Of scope by test, Need to get rid of scope label
Two 、log4j.properties Parameter Introduction
log4j.properties Need to be in resources Hierarchy creation , If it is placed in the wrong position , There may be the following explosion
log4j:WARN No appenders could be found for logger (com.xxx.xxx.LoggerFactoryDemo).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
Hierarchy demonstration
log4j.properties file
# all: Output all types of information , A: The output mode is console output
log4j.rootLogger=all, A
# Console printing
log4j.appender.A=org.apache.log4j.ConsoleAppender
log4j.appender.A.layout=org.apache.log4j.PatternLayout
log4j.appender.A.layout.ConversionPattern=%d{
yyyy-MM-dd HH:mm:ss} [%c]-[%p] %m%n
log4j.appender.B=org.apache.log4j.FileAppender
log4j.appender.B.File=E:\\young\\log.log
log4j.appender.B.layout=org.apache.log4j.SimpleLayout
# html Mode output
log4j.appender.C=org.apache.log4j.RollingFileAppender
log4j.appender.C.File=E:\\young\\log.html
log4j.appender.C.MaxFileSize=1000KB
log4j.appender.C.MaxBackupIndex=10
log4j.appender.C.layout=org.apache.log4j.HTMLLayout
log4j.appender.C.encoding=gbk
# txt Mode output
log4j.appender.D=org.apache.log4j.DailyRollingFileAppender
log4j.appender.D.File=E:\\young\\log\\log.txt
#log4j.appender.D.File=E:\\hanweb\\log\\log.txt
log4j.appender.D.layout=org.apache.log4j.TTCCLayout
3、 ... and 、Demo
Code
public class LoggerFactoryDemo {
private static final Logger logger = LoggerFactory.getLogger(LoggerFactoryDemo.class);
public static void main(String[] args) {
logger.info("this is info");
logger.error("this is error");
logger.debug("this is debug");
}
}
ConsoleAppender
2021-08-19 11:21:56 [com.xxx.service.log.LoggerFactoryDemo]-[INFO] this is info
2021-08-19 11:21:56 [com.xxx.service.log.LoggerFactoryDemo]-[ERROR] this is error
2021-08-19 11:21:56 [com.xxx.service.log.LoggerFactoryDemo]-[DEBUG] this is debug
边栏推荐
- State machine program framework
- [go ~ 0 to 1] the next day, June 25, switch statement, array declaration and traversal
- Sword finger offer 30 Stack containing min function
- Sword finger offer 03 Duplicate number in array
- yaml json
- Construire le premier réseau neuronal avec pytorch et optimiser
- WasmEdge 0.10.0 发布!全新的插件扩展机制、Socket API 增强、LLVM 14 支持
- [introduction to SQL for 10 days] day4 Combined Query & specified selection
- Robot Rapping Results Report
- Copy & Deepcopy
猜你喜欢
从知识到智慧:知识图谱还要走多远?
AWS builds a virtual infrastructure including servers and networks (2)
DB
MySQL8.0 忘记 root 密码
The 6th smart home Asia 2022 will be held in Shanghai in October
Which is a better ERP management system for electronic component sales?
VMware Workstation related issues
Infinite penetration test
[cloud native | kubernetes] in depth understanding of pod (VI)
Dell r730 server startup error: [xxx] USB 1-1-port4: disabled by hub (EMI?), re-enabling...
随机推荐
Construire le premier réseau neuronal avec pytorch et optimiser
Love analysis released the 2022 love analysis · it operation and maintenance manufacturer panorama report, and an Chao cloud was strongly selected!
What are the advantages of a differential probe over a conventional probe
Goldbach`s Conjecture
State machine program framework
利尔达低代码数据大屏,铲平数据应用开发门槛
What is the bandwidth of the Tiktok server that can be used by hundreds of millions of people at the same time?
Application of current limiting protector in preventing electrical fire in shopping malls
【无标题】
Application of energy management system in iron and steel enterprises
Privacy computing fat----- offline prediction
Which is a better ERP management system for electronic component sales?
【力扣10天SQL入门】Day5+6 合并表
[go ~ 0 to 1] on the first day, June 24, variables, conditional judgment cycle statement
yaml json
Mysql8.0 forgot the root password
批量修改表和表中字段排序规则
Operating principle of Rogowski coil
centos mysql5.5配置文件在哪
Almost union find (weighted union search)