在本章中,我们将讨论在使用SLF4J时获得的各种错误消息或警告以及这些消息的原因/含义。

无法加载类“org.slf4j.impl.StaticLoggerBinder”。

这是在类路径中没有提供SLF4J绑定时引起的警告。

以下是完整的警告 -

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.

要解决此问题,需要添加任一日志框架绑定。本教程上一小节对此进行了解释说明。

注 - 这种情况发生在SLF4J的版本中,介于1.6.0和1.8.0-beta2之间。

No SLF4J providers were found

在slf4j-1.8.0-beta2中,上述警告更清楚地说“未找到SLF4J提供商”。

以下是完整的警告 -

SLF4J: No SLF4J providers were found.

SLF4J: Defaulting to no-operation (NOP) logger implementation

SLF4J: See http://www.slf4j.org/codes.html#noProviders for further details.

Classpath包含针对1.8之前的slf4j-api版本的SLF4J绑定

如果使用的是SLF4J 1.8版本,并且在类路径中具有以前版本的绑定但没有1.8的绑定,则会看到如下所示的警告。

SLF4J: No SLF4J providers were found.

SLF4J: Defaulting to no-operation (NOP) logger implementation

SLF4J: See http://www.slf4j.org/codes.html#noProviders for further details.

SLF4J: Class path contains SLF4J bindings targeting slf4j-api versions prior to

1.8.

SLF4J: Ignoring binding found at

[jar:file:/C:/Users/maxsu/Desktop/Latest%20Yiibai/SLF4J%20Tutorial/

slf4j-1.7.25/slf4j-jdk14-1.7.25.jar!/org/slf4j/impl/StaticLoggerBinder.class]

SLF4J: See http://www.slf4j.org/codes.html#ignoredBindings for an explanation.

NoClassDefFoundError: org/apache/commons/logging/LogFactory

如果正在使用slf4j-jcl,并且类路径中只有slf4j-jcl.jar,将得到一个例外(异常),例如下面给出的例外(异常)。

Exception in thread "main" java.lang.NoClassDefFoundError:

org/apache/commons/logging/LogFactory

at org.slf4j.impl.JCLLoggerFactory.getLogger(JCLLoggerFactory.java:77)

at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:358)

at SLF4JExample.main(SLF4JExample.java:8)

Caused by: java.lang.ClassNotFoundException:

org.apache.commons.logging.LogFactory

at java.net.URLClassLoader.findClass(Unknown Source)

at java.lang.ClassLoader.loadClass(Unknown Source)

at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)

at java.lang.ClassLoader.loadClass(Unknown Source)

... 3 more

要解决此问题,需要将commons-logging.jar添加到类路径中。

Detected both jcl-over-slf4j.jar AND bound slf4j-jcl.jar on the classpath..

绑定slf4j-jcl.jar将slf4j logger的调用重定向到JCL,jcl-over-slf4j.jar将JCL logger的调用重定向到slf4j。因此,不能在项目的类路径中同时拥有这两者。如果这样做,会得到一个例外(异常),例如下面给出的(异常)。

SLF4J: Detected both jcl-over-slf4j.jar AND bound slf4j-jcl.jar on the class

path, preempting StackOverflowError.

SLF4J: See also http://www.slf4j.org/codes.html#jclDelegationLoop for more

details.

Exception in thread "main" java.lang.ExceptionInInitializerError

at org.slf4j.impl.StaticLoggerBinder.(StaticLoggerBinder.java:71)

at org.slf4j.impl.StaticLoggerBinder.(StaticLoggerBinder.java:42)

at org.slf4j.LoggerFactory.bind(LoggerFactory.java:150)

at org.slf4j.LoggerFactory.performInitialization(LoggerFactory.java:124)

at org.slf4j.LoggerFactory.getILoggerFactory(LoggerFactory.java:412)

at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:357)

at SLF4JExample.main(SLF4JExample.java:8)

Caused by: java.lang.IllegalStateException: Detected both jcl-over-slf4j.jar

AND bound slf4j-jcl.jar on the class path, preempting StackOverflowError. See

also http://www.slf4j.org/codes.html#jclDelegationLoop for more details.

at org.slf4j.impl.JCLLoggerFactory.(JCLLoggerFactory.java:54)

... 7 more

要解决此问题,请删除其中一个jar文件。

Detected logger name mismatch

可以通过以下方式创建Logger对象:

将要创建的记录器的名称作为参数传递给getLogger()方法。

将类作为参数传递给此方法。

如果通过将类作为参数传递来创建记录器工厂对象,并且已将系统属性slf4j.detectLoggerNameMismatch设置为true,那么作为参数传递给getLogger()方法的类的名称和使用类应该相同,否则将收到以下警告 -

“Detected logger name mismatch”

请考虑以下示例。

import org.slf4j.Logger;

import org.slf4j.LoggerFactory;

public class SLF4JExample {

public static void main(String[] args) {

System.setProperty("slf4j.detectLoggerNameMismatch", "true");

//Creating the Logger object

Logger logger = LoggerFactory.getLogger(Sample.class);

//Logging the information

logger.info("Hi Welcome to Yiibai.com");

}

}

在这里,将slf4j.detectLoggerNameMismatch属性设置为true。使用的类的名称是SLF4JExample,传递给getLogger()方法的类名是Sample,因为它们都不相等,将会收到以下警告。

SLF4J: Detected logger name mismatch. Given name: "Sample"; computed name:

"SLF4JExample".

SLF4J: See http://www.slf4j.org/codes.html#loggerNameMismatch for an

explanation

Dec 10, 2019 10:23:00 PM SLF4JExample main

INFO: Hi Welcome to Yiibai.com

注 - 它在slf4j 1.7.9之后发生

Classpath contains multiple SLF4J bindings.

应该在类路径中只有一个绑定。如果有多个绑定,将收到一个警告,列出绑定及其位置。

假设,如果在类路径中有绑定slf4j-jdk14.jar和slf4j-nop.jar,将收到以下警告。

SLF4J: Class path contains multiple SLF4J bindings.

SLF4J: Found binding in

[jar:file:/C:/Users/Yiibai/Desktop/Latest%20Yiibai/SLF4J%20Tutorial/

slf4j-1.7.25/slf4j-nop-1.7.25.jar!/org/slf4j/impl/StaticLoggerBinder.class]

SLF4J: Found binding in

[jar:file:/C:/Users/Yiibai/Desktop/Latest%20Yiibai/SLF4J%20Tutorial/

slf4j-1.7.25/slf4j-jdk14-1.7.25.jar!/org/slf4j/impl/StaticLoggerBinder.class]

SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an

explanation.

SLF4J: Actual binding is of type [org.slf4j.helpers.NOPLoggerFactory]

Detected both log4j-over-slf4j.jar AND bound slf4j-log4j12.jar on the class path

要将log4j logger调用重定向到slf4j,需要使用log4j-over-slf4j.jar绑定,如果要将slf4j调用重定向到log4j,则需要使用slf4j-log4j12.jar绑定。

因此,不能在类路径中同时拥有这两者。如果这样做,将收到以下异常。

SLF4J: Detected both log4j-over-slf4j.jar AND bound slf4j-log4j12.jar on the

class path, preempting StackOverflowError.

SLF4J: See also http://www.slf4j.org/codes.html#log4jDelegationLoop for more

details.

Exception in thread "main" java.lang.ExceptionInInitializerError

at org.slf4j.impl.StaticLoggerBinder.(StaticLoggerBinder.java:72)

at org.slf4j.impl.StaticLoggerBinder.(StaticLoggerBinder.java:45)

at org.slf4j.LoggerFactory.bind(LoggerFactory.java:150)

at org.slf4j.LoggerFactory.performInitialization(LoggerFactory.java:124)

at org.slf4j.LoggerFactory.getILoggerFactory(LoggerFactory.java:412)

at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:357)

at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:383)

at SLF4JExample.main(SLF4JExample.java:8)

Caused by: java.lang.IllegalStateException: Detected both log4j-over-slf4j.jar

AND bound slf4j-log4j12.jar on the class path, preempting StackOverflowError.

See also http://www.slf4j.org/codes.html#log4jDelegationLoop for more details.

¥ 我要打赏

纠错/补充

收藏

加QQ群啦,易百教程官方技术学习群

注意:建议每个人选自己的技术方向加群,同一个QQ最多限加 3 个群。

linux slf4j找不到,SLF4J错误消息相关推荐

  1. linux slf4j找不到,slf4j+log4j2在tomcat8 下无日志输出

    evn: linux && intellij && openjdk 1.7 && tomcat 8 maven 配置: org.apache.loggi ...

  2. 在 Linux 上找出并解决程序错误的主要方法【转】

    在 Linux 上找出并解决程序错误的主要方法[转] 参考文章: (1)在 Linux 上找出并解决程序错误的主要方法[转] (2)https://www.cnblogs.com/sky-heaven ...

  3. 0X8009310B (ASN:276) win7安装证书时出现错误消息:找不到与此证书文件相关联的证书申请微软官方文档

    原文:http://support.microsoft.com/kb/959216#top 您尝试通过使用 IIS 7.0 管理器安装证书时出现错误消息:"找不到与此证书文件相关联的证书申请 ...

  4. 如何处理错误消息Please install the Linux kernel header files

    Please install the Linux kernel "header" files matching the current kernel 当我启动minilkube时遇 ...

  5. linux没权限ttl连接后,如何在没有root权限的Linux上从C中的UDP数据包中找回TTL超出的错误消息?...

    设置UDP套接字选项: on = IP_PMTUDISC_DO; // sets the Don't-Fragment flag setsockopt(fd, SOL_IP, IP_MTU_DISCO ...

  6. linux C语言perror()函数(将错误消息写入标准错误)(把一个描述性错误消息输出到标准错误 stderr。首先输出自定义字符串 str,后跟一个冒号,然后是一个空格)

    文章目录 man 3 perror man 3posix perror 20220723 C语言 | perror函数使用详解 man 3 perror PERROR(3) Linux Program ...

  7. 访问在 WINS 数据库时的错误消息: 找不到 WINS 服务器

    问题: 当您试图访问 WINS 数据库在本地 WINS 服务器上的安装 Windows Internet 名称服务 (WINS) 组件后,您可能会收到以下错误消息: 找不到 WINS 服务器. 找不到 ...

  8. linux显示fio为非法指令,FORTRAN运行错误消息列表中英对照.doc

    FORTRAN运行错误消息列表中英对照 Fortran的运行时错误消息列表 本节列出了英特尔Fortran运行时库(RTL)处理的错误.对于每一个错误,该表提供了错误号,严重性代码,错误信息文本,条件 ...

  9. 什么是好的错误消息? 讨论一下Java系统中的错误码设计

    简介:一个好的Error Message主要包含三个部分:Context: 什么导致了错误?发生错误的时候代码想做什么?The error itself: 到底是什么导致了失败?具体的原因和当时的数据 ...

最新文章

  1. university, school, college, department, institute的区别
  2. Tensorflow杂记
  3. R语言dplyr包使用select函数通过索引查询或者排除数据列实战(Select Columns by Index)
  4. python类中方法的执行顺序-Python中实例化class的执行顺序示例详解
  5. AI之FL:联邦学习(Federated Learning)的简介、入门、应用之详细攻略
  6. PMP知识点(二、整合管理)
  7. distcc源码研究三
  8. 6a标准 api_【阀门标准】API SPEC 6A CHINESE-2010中文版.pdf
  9. 蓝凌ekp开发_蓝凌OA系统,蓝凌EKP,蓝凌KK__房地产案例应用__恒大集团
  10. 用C#实现MVC(Model View Control)模式介绍
  11. 【渝粤教育】国家开放大学2018年春季 8668-22T汽车涂装技术(A) 参考试题
  12. 讲解浏览器 三次握手四次挥手。
  13. 微信表情包储服务器,新发现!微信里的表情包,终于能保存到手机和电脑辣!-qq表情在哪个文件夹里...
  14. 获取所有QQ好友列表以及好友信息
  15. 职场新人注意事项:抖包袱可以,抖机灵不要
  16. 截止频率的估算-例题
  17. ES摄入性能优化(插入提高了2倍+ 17w/s到37w/s)
  18. ZOJ 142 - The 14th Zhejiang Provincial Collegiate Programming Contest Sponsored by TuSimple - D
  19. 企业信息怎么查询?企业工商信息查询技巧
  20. SAP销售订单历史修改后台表

热门文章

  1. 检索数据_19_按照字符串对结果排序
  2. python 标签云_标签云算法Python实现
  3. 深入浅出之C++11新特性
  4. Android持久化存储(2)SharedPreferences使用介绍
  5. Windows下MariaDB数据库安装图文教程
  6. ICS—CERT官网公示匡恩网络新发现四工控漏洞
  7. 快速求平方根,这个好牛逼
  8. (转载)一套完整的UI设计规范手册(IOS版)
  9. HDU_2795 Billboard(线段树)
  10. DELL台式机BIOS常见问题