将项目从log4j迁移到slf4j + log4j [英] migrating a project from log4j to slf4j+log4j

查看:123
本文介绍了将项目从log4j迁移到slf4j + log4j的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个直接使用log4j的大型Web项目,以及许多第三方库和各种日志库。

I have a large web project that uses log4j directly, together with many 3rd-party libraries and a mix of logging libraries.


  • 我们的代码库 - 直接使用log4j。

  • Hibernate - 使用slf4j和slf4j-log4j绑定。

  • Spring - 使用commons-loggings。因此,它使用jcl-over-slf4j桥接api,slf4j本身和slf4j-log4j绑定。

  • 其他众多库,使用commons loggings或log4j。

  • our code base - uses log4j directly.
  • Hibernate - uses slf4j, and the slf4j-log4j binding.
  • Spring - uses commons-loggings. Thus, it uses the jcl-over-slf4j bridge api, slf4j itself, and slf4j-log4j binding.
  • Other numerous libraries, using either commons loggings or log4j.

我正在考虑将我们自己的代码库迁移到slf4j api,但我不确定这些好处是否足够强大且值得付出努力。目前我知道以下好处:

I am considering migrating our own code base to slf4j api, but I am not sure if the benefits are strong enough and worth the effort. Currently I am aware of the following benefits:


  • 清洁api。

  • 性能改进 - 即使用参数化日志记录方法的能力。

  • 将来可以轻松切换到logback(目前无法进行回退)。

  • 不需要对于额外的罐子,因为我已经拥有它们。

  • Cleaner api.
  • Performance improvements - namely the ability to use parameterized logging methods.
  • Ability to switch easily to logback in the future (currently logback is out of the question).
  • No need for additional jars, since I already have them.

还有其他好处吗?是否有任何我不知道的缺点?

Are there any other benefits? Are there any drawbacks that I am not aware of yet?

推荐答案

我看到切换的唯一好处就是你可以漏斗了所有日志框架只通过一个框架,这可能会简化您的配置。

The only benefit I see for switching, is that you can funnel all the logging frameworks through only one framework, which might simplify your configuration.

我搬到slf4j的主要原因(这只适用于slf4j + logback)可能是你可以通过JMX重新加载配置,当你的服务器重启时出现问题时,这是很好的。

Probably the main reasons why I moved to slf4j (this only applies to slf4j + logback) is that you can reload the configuration via JMX, which is GREAT when you have a problem that disappears with a server restart.

这篇关于将项目从log4j迁移到slf4j + log4j的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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