当前位置:网站首页>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
边栏推荐
- Using transform:scale causes the page mouse hover event to disappear
- 小程序 :遍历list里面的某个数组的值,等同于 for=“list” list.comment里面的某一项
- Error: `brew cask` is no longer a `brew` command. Use `brew <command> --cask` instead.
- How to solve the problem of high concurrency and seckill
- MATLAB小技巧(20)矩阵分析--主成分回归
- DEJA_VU3D - Cesium功能集 之 052-模拟卫星轨道(高空)效果
- temple
- AWS builds a virtual infrastructure including servers and networks (2)
- 为什么函数模板没有偏特化?
- Implementation of code scanning login
猜你喜欢

STL -- binder

How to suppress SiC MOSFET crosstalk?

webrtc优势与模块拆分

用Pytorch搭建第一个神经网络且进行优化

Application of energy management system in iron and steel enterprises

containerd1.5.5的安装

TCP

"Jianzhi offer" -- Interview Question 4: finding two-dimensional arrays

【.NET6】gRPC服务端和客户端开发案例,以及minimal API服务、gRPC服务和传统webapi服务的访问效率大对决

如何抑制SiC MOSFET Crosstalk(串擾)?
随机推荐
广州:金融新活水 文企新机遇
Implement global double finger long press to return to the desktop
Goldbach`s Conjecture
实现全局双指长按返回桌面
STL -- binder
Why are function templates not partial specialization?
Goldbach`s Conjecture
Superimposed ladder diagram and line diagram and merged line diagram and needle diagram
神殿
webrtc优势与模块拆分
CloudCompare&PCL 点云裁剪(基于封闭曲面或多边形)
状态机程序框架
Zhejiang energy online monitoring and management system
Lilda low code data large screen, leveling the threshold of data application development
What is the bandwidth of the Tiktok server that can be used by hundreds of millions of people at the same time?
Analysis of prepaid power purchase device
State machine program framework
Quelle est la largeur de bande du serveur de bavardage sonore pour des centaines de millions de personnes en même temps?
Build an integrated kubernetes in Fedora
Fire safety hazards