用Java登录怎么办? [英] What's Up with Logging in Java?
本文介绍了用Java登录怎么办?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
为什么一个将使用以下软件包之一而不是另一个?
Why one would use one of the following packages instead of the other?
- Java记录
- 常用日志记录
- Log4j
- SLF4j
- 登录
推荐答案
按照api出现的时间顺序(据我所知):
In chronological order of api apperance (as far as I know):
- Log4j,因为大多数人都使用它(以我的经验)
- 公用日志记录,因为开放源代码项目使用它(因此它们可以与集成解决方案中使用的任何日志记录框架集成);如果您使用的是API/Framework/OSS,并且依赖于使用Commons Logging的其他软件包,则尤其有效.
- 公共日志记录是因为您不想锁定"到特定的日志记录框架(因此,您可以锁定到Commons Logging为您提供的功能)-我认为决定使用这一点是不明智的原因.
- Java日志记录,因为您不想添加额外的jar.
- SLF4j,因为它比Commons Logging更新并且提供了参数化的日志记录:
logger.debug("The entry is {}.", entry);
//which expands effectively to
if (logger.isDebugEnabled()){
// Note that it's actually *more* efficient than this - see Huxi's comment below...
logger.debug("The entry is " + entry + ".");
}
- Logback,因为它比log4j更新,并且再次支持参数化日志记录,因为它直接实现了SLF4j
- SLF4j/Logback是因为它是由做log4j的同一个人编写的,因此他的表现更好(根据他们较早的新闻)
- SLF4j,因为它们还发布了log4j适配器,因此您不必在旧代码中切换" log4j-只需使log4j.properties使用SLF4j及其配置即可.
- Logback because it's newer than log4j and again, supports parameterized logging, as it implements SLF4j directly
- SLF4j/Logback because it's written by the same guy who did log4j, so he's made it better (according to Ken G - thanks. It seems to fit when looking at their earlier news posts)
- SLF4j because they also publish a log4j adapter so you don't have to "switch out" log4j in older code - just make log4j.properties use SLF4j and it's configuration
这篇关于用Java登录怎么办?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文