log4j 与 logback [英] log4j vs logback

查看:37
本文介绍了log4j 与 logback的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们在自制包装器后面使用 log4j.我们现在计划使用它的更多功能.

We are using log4j behind a selfmade wrapper. We plan to use much more features of it now.

我们应该更新到 logback 吗?

Should we update to logback ?

(我的意思是框架不是像 SLF4J 这样的门面)

(I mean the framework not a facade like SLF4J)

推荐答案

Logback 原生实现了 SLF4J API.这意味着如果您使用的是 logback,那么您实际上是在使用 SLF4J API.理论上,您可以直接使用 logback API 的内部结构进行日志记录,但强烈建议不要这样做.所有关于记录器的 logback 文档和示例都是根据 SLF4J API 编写的.

Logback natively implements the SLF4J API. This means that if you are using logback, you are actually using the SLF4J API. You could theoretically use the internals of the logback API directly for logging, but that is highly discouraged. All logback documentation and examples on loggers are written in terms of the SLF4J API.

因此,通过使用 logback,您实际上是在使用 SLF4J,如果出于任何原因您想切换回 log4j,只需将 slf4j-log4j12.jar 放到您的类路径中,您就可以在几分钟内完成.

So by using logback, you'd be actually using SLF4J and if for any reason you wanted to switch back to log4j, you could do so within minutes by simply dropping slf4j-log4j12.jar onto your class path.

当从 logback 迁移到 log4j 时,logback 特定的部分,特别是那些包含在 logback.xml 配置文件中的部分,仍然需要迁移到它的 log4j 等价物,即 log4j.propertiesem>.当向另一个方向迁移时,log4j 配置,即 log4j.properties,需要转换为其等效的 logback.有一个在线工具.迁移配置文件所涉及的工作量远少于迁移在所有软件源代码及其依赖项中传播的记录器调用所需的工作量.

When migrating from logback to log4j, logback specific parts, specifically those contained in logback.xml configuration file would still need to be migrated to its log4j equivalent, i.e. log4j.properties. When migrating in the other direction, log4j configuration, i.e. log4j.properties, would need to be converted to its logback equivalent. There is an on-line tool for that. The amount of work involved in migrating configuration files is much less than the work required to migrate logger calls disseminated throughout all your software's source code and its dependencies.

这篇关于log4j 与 logback的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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