当前位置:网站首页>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
边栏推荐
- Cloudcompare & PCL point cloud clipping (based on closed surfaces or polygons)
- A - 深海探险
- centos mysql5.5配置文件在哪
- Ffmpeg streaming fails to update header with correct duration
- Guangzhou: new financial activities and new opportunities for enterprises
- [.Net6] GRP server and client development cases, as well as the access efficiency duel between the minimum API service, GRP service and traditional webapi service
- Trailing Zeroes (II)
- Applet: traverse the value of an array in the list, which is equivalent to for= "list" list An item in comment
- WasmEdge 0.10.0 发布!全新的插件扩展机制、Socket API 增强、LLVM 14 支持
- MATLAB小技巧(20)矩阵分析--主成分回归
猜你喜欢

MATLAB小技巧(20)矩阵分析--主成分回归

Construire le premier réseau neuronal avec pytorch et optimiser
![[.Net6] GRP server and client development cases, as well as the access efficiency duel between the minimum API service, GRP service and traditional webapi service](/img/19/296f124becb87461accf8b73b0a8bc.png)
[.Net6] GRP server and client development cases, as well as the access efficiency duel between the minimum API service, GRP service and traditional webapi service

抖音服務器帶寬有多大,才能供上億人同時刷?

Wasmedge 0.10.0 release! New plug-in extension mechanism, socket API enhancement, llvm 14 support

WasmEdge 0.10.0 发布!全新的插件扩展机制、Socket API 增强、LLVM 14 支持

AWS builds a virtual infrastructure including servers and networks (2)

STL -- binder

Using transform:scale causes the page mouse hover event to disappear

【云原生 | Kubernetes篇】深入了解Pod(六)
随机推荐
APICloud携手三六零天御,助力企业守好App安全“第一关”
A - 深海探险
用Pytorch搭建第一个神经网络且进行优化
抖音服务器带宽有多大,才能供上亿人同时刷?
Solution: selenium common. exceptions. WebDriverException: Message: ‘chromedriver‘ execu
Power data
三体攻击(三维拆分加二分)
Super Jumping! Jumping! Jumping!
Love analysis released the 2022 love analysis · it operation and maintenance manufacturer panorama report, and an Chao cloud was strongly selected!
Why are function templates not partial specialization?
[untitled]
CloudCompare&PCL 点云裁剪(基于封闭曲面或多边形)
Tree
个人究竟如何开户炒股?在线开户安全么?
Quickly understand JVM structure and working principle
【大案例】学成在线网站
【无标题】
批量修改表和表中字段排序规则
Using transform:scale causes the page mouse hover event to disappear
【力扣10天SQL入门】Day5+6 合并表