当前位置:网站首页>slf4j如何进行logback配置呢?
slf4j如何进行logback配置呢?
2022-07-27 07:34:00 【qq_25073223】
转自:
slf4j简介:
slf4j,simple logging facade for java的缩写,翻译为java的简单日志外观。slf4j是一个开源项目,它提供我们一个一致的API来使用不同的日志框架,比如: java.util.logging,logback,log4j等。slf4j使用户可以在运行时嵌入他们想使用的日志框架。从名字中可以看出,它其实使用的是facade设计模式来实现的。
使用slf4j,只有一个强制性的依赖,就是slf4j-api-x.x.x.jar,我们在编写代码的时候,只会使用这个jar包里的API,应用程序在运行时去类路径下查找绑定的具体日志框架,并使用该绑定的日志框架进行实际的日志操作,如果在应用程序的类路径下面没有找到合适的绑定的话,slf4j默认使用一个没有任何操作的实现。
下文讲述slf4j中配置logback的方法分享,如下所示:
步骤一:pom.xml添加logback依赖
<dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-api</artifactId> <version>1.7.25</version> </dependency> <dependency> <groupId>ch.qos.logback</groupId> <artifactId>logback-classic</artifactId> <version>1.2.3</version> </dependency> <dependency> <groupId>ch.qos.logback</groupId> <artifactId>logback-core</artifactId> <version>1.2.3</version> </dependency>
步骤二:配置logback
logback配置详见logback.xml完整配置文件
编写测试代码
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class LoggerTest {
private static final Logger logger = LoggerFactory.getLogger(LoggerTest.class);
public static void main(String[] args) {
logger.error("严重警告");
logger.warn("警告");
logger.info("普通信息");
logger.debug("调试信息");
}
}边栏推荐
- Comprehensive analysis of ADC noise-01-types of ADC noise and ADC characteristics
- UUID and secrets module
- 【StoneDB Class】入门第一课:数据库知识科普
- Examples of Oracle triggers
- MySQL backup strategy
- 正则 和 sed 练习
- C common function integration-3
- Codeforces Round #810 (Div.2) A-C
- RPC remote procedure call
- Regular expression foundation sorting
猜你喜欢
随机推荐
DEMO:PA30 银行国家码默认CN 增强
Regular and sed exercises
Okaleido生态核心权益OKA,尽在聚变Mining模式
Flink de duplication (I) summary of common de duplication schemes in Flink and Flink SQL
UUID and secrets module
Multithreading [preliminary - Part 1]
RPC 远程过程调用
Shell condition test, judgment statement and operator of shell system learning
Panabit SNMP configuration
电子量产项目框架--基本思想
Prior Attention Enhanced Convolutional Neural Network Based Automatic Segmentation of Organs at Risk
什么是真正的HTAP?(一)背景篇
帮忙发一份招聘,base全国,有兴趣的可以过来看看
User unlock sm04 sm12
Showdoc vulnerability learning - cnvd-2020-26585 (arbitrary file upload)
Resttemplate connection pool configuration
杂谈:手里有竿儿,肩上有网,至于背篓里有多少鱼真的重要吗?
Understanding and learning of node flow and processing flow in io
Am I delayed by the code... Unfortunately, I became a programmer
Bash: create a function that returns a Boolean value








