1. slf4j-api slf4j:Simple Logging Facade for Java,为java提供的简单日志Facade。Facade门面,更底层一点说就是接口。 具体有哪些接口,全部都定义在slf4j-api中。查看slf4j-api源码就可以发现,里面除了public final class LoggerFactory类之外,都是接口定义。 因此slf4j-api本质就是一个接口定义。 首先系统包含slf4j-api作为日志接入的接口:编译时slf4j-api中public final class LoggerFactor类中private final static void bind 2. slf4j-log4j12是链接slf4j-api和log4j中间的适配器:它实现了slf4j-api中StaticLoggerBinder接口,从而使得在编译时绑定的是slf4j-log4j12
报错如下: Could not transfer artifact org.slf4j:slf4j-api:jar:1.6.4 from/to central (https://repo.maven.apache.org protocol_version org.eclipse.aether.transfer.ArtifactTransferException: Could not transfer artifact org.slf4j:slf4j-api
{ //排除某一个库(slf4j)依赖:如下三种写法都行 exclude group: 'org.slf4j' exclude module: 'slf4j-api ' exclude group: 'org.slf4j',module: 'slf4j-api' } //排除之后,使用手动的引入即可。 /不允许依赖传递,一般不用 transitive(false) } //排除之后,使用手动的引入即可 implementation 'org.slf4j:slf4j-api 【官方建议使用这种方式】 implementation('org.slf4j:slf4j-api:1.4.0!!') //这种效果和上面那种一样,强制指定某个版本 implementation('org.slf4j:slf4j-api:1.4.0'){ version{
slf4j-api.jar. http://www.slf4j.org/ <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-api POM 依赖:slf4j-api 通过 slf4j-log4j12 绑定到 log4j1.2; <dependency> <groupId>org.slf4j</groupId> < artifactId>slf4j-api</artifactId> <version>1.7.29</version> </dependency> <dependency> <groupId ; } } 运行结果: POM 依赖:slf4j-api 通过 log4j-slf4j-impl 绑定到 log4j2; <dependency> <groupId>org.slf4j -- slf4j api --> <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-api</artifactId>
1.1.11 | | | | +--- ch.qos.logback:logback-core:1.1.11 | | | | \--- org.slf4j:slf4j-api 1.7.22 -> 1.7.26 | | | +--- org.slf4j:jcl-over-slf4j:1.7.26 | | | | \--- org.slf4j:slf4j-api :1.7.26 | | | +--- org.slf4j:jul-to-slf4j:1.7.26 | | | | \--- org.slf4j:slf4j-api :1.7.26 | | | \--- org.slf4j:log4j-over-slf4j:1.7.26 | | | \--- org.slf4j:slf4j-api
groupId>com.google.protobuf</groupId> </exclusion> <exclusion> <artifactId>slf4j-api <version>${flink.version}</version> <exclusions> <exclusion> <artifactId>slf4j-api </groupId> </exclusion> <exclusion> <artifactId>slf4j-api </groupId> </exclusion> <exclusion> <artifactId>slf4j-api </groupId> </exclusion> <exclusion> <artifactId>slf4j-api
logback.qos.ch/ https://logback.qos.ch/manual/index.html logback手册 1.下载 logback是slf4j的原生实现,所以在使用logback时,必须配置slf4j-api 具体来说,必须依赖3个组件:slf4j-api,logback-core,logback-classic。 <dependencies> <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-api</artifactId>
问题描述 项目使用Spring Boot框架,在pom文件中添加了如下配置: <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-api 原因追踪 追踪slf4j-api的源码发现,当classpath路径存在slf4j-simple时,是一定会优先加载其中的org.slf4j.impl.StaticLoggerBinder类的。 也就是说,当slf4j-simple存在classpath下时,总是优先使用它作为slf4j-api的默认实现;此时,即使同时配置了log4j,也无法使用log4j进行日志输出。 -- 使用loback作为slf4j的日志实现组件 --> <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-api -- logback无法与slf4j-simple共存 --> <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-api
mapper.convertValue(list, new TypeReference<List<Task>>() {}); 3、解决依赖冲突: 方式1: 排除传递依赖 compile 'org.slf4j:slf4j-api org.hibernate:hibernate-core:3.6.3.Final'){ //排除某一个库(slf4j)依赖 exclude group: 'org.slf4j',module: 'slf4j-api org.hibernate:hibernate-core:3.6.3.Final') { //指定禁止传递依赖 transitive false } compile 'org.slf4j:slf4j-api configurations.all() { Configuration configuration -> configuration.resolutionStrategy.force(['org.slf4j:slf4j-api :1.6.1']) //或者这样写 resolutionStrategy.setForcedModules(['org.slf4j:slf4j-api:
www.slf4j.org/codes.html#noProviders for further details.SLF4J: Class path contains SLF4J bindings targeting slf4j-api <dependency><groupId>org.slf4j</groupId><artifactId>slf4j-api</artifactId><version>1.7.33</version></
.EAP Maven 3.5.2 Spring Framework 注明: 本文基于Spring Framework环境,并非基于SpringBoot.如果是基于SpringBoot,因为默认加入了Slf4j-api -- https://mvnrepository.com/artifact/org.slf4j/slf4j-api --> <dependency> <groupId>org.slf4j</groupId > <artifactId>slf4j-api</artifactId> <version>1.7.25</version> </dependency> <!
-- https://mvnrepository.com/artifact/org.slf4j/slf4j-api --> <dependency> <groupId>org.slf4j</groupId > <artifactId>slf4j-api</artifactId> <version>1.7.25</version> </dependency> <!
logging/log4j/2.17.2/apache-log4j-2.17.2-bin.tar.gz tar xf apache-log4j-2.17.2-bin.tar.gz 2、同时下载要替换的slf4j-api 1.7.32版本jar包 wget --no-check-certificate https://repo1.maven.org/maven2/org/slf4j/slf4j-api/1.7.32/slf4j-api -Ei 'log4j|slf' log4j-1.2.17.jar slf4j-api-1.7.25.jar slf4j-log4j12-1.7.25.jar 然后分别删除slf4j-log4j12、slf4j-api logging/log4j/2.17.2/apache-log4j-2.17.2-bin.tar.gz tar xf apache-log4j-2.17.2-bin.tar.gz 2、同时下载要替换的slf4j-api 1.7.32版本jar包 wget --no-check-certificate https://repo1.maven.org/maven2/org/slf4j/slf4j-api/1.7.32/slf4j-api
artifactId>feign-slf4j</artifactId> <version>${feign.version}</version> </dependency> 该模块会携带依赖包:slf4j-api 注意:core部分并不依赖于slf4j-api部分 logback-classic:实现了Slf4j的API,所以当想配合Slf4j使用时,需要引入logback-classic。 它会依赖于slf4j-api部分,所以可以说是天然支持 logback-access:为了集成Servlet环境而准备的,可提供HTTP-access的日志接口。 一般情况下都用不到(但有研究价值) ---- 使用示例 在POM文件里,按照上面GAV,导入logback-classic这个Jar(包含slf4j-api和logback-core),这样就简单的直接生效了 说明:不吹不黑,slf4j-api这种SPI方式也挺有意思的:完全通过路径名类加载 + 异常捕获方式来确定具体实现,完成自动绑定。
前言 在日志框架slf4j中有一组项目,除了核心的slf4j-api之外,还有slf4j-log4j12、slf4j-jdk14等项目。 slf4j时,除了需要引入log4j的jar包依赖,还需要引入slf4j的下面两个依赖: <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-api <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-log4j12</artifactId> </dependency> slf4j-api 总之,slf4j的Logger接口的方法通过Log4jLoggerAdapter进行包装和转换,交由log4j的Logger去执行,这就达到了连接slf4j-api和log4j的目的。 而此时,slf4j-api不并关系日志是如何实现记录,对此也无感知。
--slf4j 核心依赖--> <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-api</artifactId> e.printStackTrace(); logger.info("具体错误是:", e); } } 输出结果: 3、绑定日志的实现 使用slf4j绑定日志的流程 添加slf4j-api --slf4j 核心依赖--> <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-api</artifactId> --slf4j 核心依赖--> <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-api</artifactId> -- 导入log4j适配器依赖 slf4j-log4j12依赖的slf4j-api,slf4j-api可以不用重复导入依赖 --> <dependency> <groupId>org.slf4j
1. binding module 如果当前应用的classpath下不仅有日志系统,而且还有与该日志系统匹配的绑定模块,那么面向 slf4j-api 的日志记录请求最终会被路由到该日志系统中去。 细心点的同学应该能发现,在 slf4j-api 和一众绑定模块中,均含有org/slf4j/impl/StaticLoggerBinder.java,那么如何确保一定是绑定模块中的StaticLoggerBinder slf4j-api 模块在打包的时候会排除掉该 Class 文件。另外,StaticLoggerBinder.getSingleton() 这一行代码究竟有何深意呢? getLoggerFactory() 方法返回的是JDK14LoggerFactory,JDK14LoggerFactory 是绑定模块 slf4j-jdk14 提供的,其实现了 slf4j-api 中的 从这个例子中,大家可能猜到了桥接模块的作用,就是将面向特定日志系统的日志记录请求路由到 slf4j-api 中去。
日志 正常输出 ; 在 根目录的 pom.xml 中 , 添加如下依赖 : <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-api </dependency> <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-api
SLF4J: slf4j-api 1.6.x (or later) is incompatible with this binding. implementation (class org.slf4j.helpers.NOPLoggerFactory loaded from file:/Users/jack/.m2/repository/org/slf4j/slf4j-api
Note that these providers must target slf4j-api 1.8 or later. Please note that slf4j-api version 1.8.x and later use the ServiceLoader mechanism. Class path contains SLF4J bindings targeting slf4j-api versions prior to 1.8 Planning for the advent of Jigsaw (Java 9), slf4j-api version 1.8.x and later use the ServiceLoader mechanism. NOTE From the client's perspective all versions of slf4j-api are compatible.