Log4j是否被抛弃而支持Slf4j? [英] Is Log4j being abandoned in favor of Slf4j?

查看:109
本文介绍了Log4j是否被抛弃而支持Slf4j?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

似乎log4j有一些类加载问题(等等)在我看来,趋势是从log4j移出slf4j。 (Hibernate停止使用第一个支持后者)

It seems that log4j has some class loading issues (among others) and it seems to me the trend is to move out of log4j toward slf4j. (Hibernate stopped using the first in favor of the latter)


  1. 这是真的吗?

  2. 什么是stlf4j解决的log4j中的主要问题吗?

  3. slf4j是最后一个字还是更好的下一个下一个log4j行业标准?

更新:


  • 所以这个答案让我感到困惑,你能接受/反对吗?:

  • So this answer by delfuego confuses me, can you accept / object it?:

您似乎偶然发现了log4j的
主要问题(以及
Apache Commons Logging库),
即他们有一个可笑的
难以发现并与正确的类加载器交互
,因为他们使用的是
。有一个非常密集的
解释,附有例子,这里是
; 带回家的消息是

的主要驱动力之一新的日志框架SLF4J到
完全消除了这些问题。

可能想换掉它,看看
你的生活是否变得更容易。

You appear to have stumbled upon the major problem with log4j (and the Apache Commons Logging library), namely that they have a ridiculously hard time discovering and interacting with the right classloaders as they're being used. There's a very dense explanation, complete with examples, here; the take-home message is that one of the primary driving forces for the new logging framework SLF4J was to eliminate these issues entirely. You might want to swap it in and see if your life is made any easier.




  • log4j的更多类加载问题: http://articles.qos.ch/classloader.html

    • More classloading issues by log4j: http://articles.qos.ch/classloader.html
    • 推荐答案

      Slf4j确实只是一个日志记录。但是,Log4j旨在由来自同一作者的 Logback 继承。

      Slf4j is indeed just a logging facade. However, Log4j is intended to be succeeded by Logback, from the very same authors.

      更新:如果您想了解Slf4j的另一个好处,那就是不再需要以下(丑陋)构造来避免<$ strong c $ c> toString()不必要地被调用:

      Update: if you'd like to know about another benefit of Slf4j, it's the fact that following (ugly) constructs aren't needed anymore to avoid the toString() unnecessarily been called:

      if (logger.isDebugEnabled()) {
          logger.debug("Message: " + bigObject + ", " + anotherBigObject);
      }
      

      您可以改为使用参数化消息:

      You can instead make use of parameterized messages:

      logger.debug("Message: {}, {}", bigObject, anotherBigObject);
      

      另见(不)记录的最快方法是什么?

      这篇关于Log4j是否被抛弃而支持Slf4j?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆