SLF4J调试级配置+ Logging框架集成 [英] SLF4J debugging level configuration + Logging framework integration

查看:478
本文介绍了SLF4J调试级配置+ Logging框架集成的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在考虑使用SLF4j集成多个日志框架。



java.util.logging.Logger 类有一个名为setLevel(Level newLevel)的nice方法。它在类级别启用日志配置,这有助于创建可读和精简的跟踪。



我在SLF4J框架中找不到等效的。有没有? SLF4J Logger接口不提供这种方法。我已经看过StackOverflow的其他问题,我已经阅读SL4F文档,但我不能得出一个确定的结论。



如果SLF4J不允许微调我在寻找,那么SLF4J的真正好处是什么?它似乎剥离了绑定框架的有趣的功能到一个最常见的弱和无用的分母...



如果是这样,为什么不应该将我的所有代码转换为我的喜欢的日志框架而不是SLF4J?



编辑



<可能是我自私的抱怨SLF4J没有回答我希望在这里。然而,我仍然没有看到使用SLF4j集成日志框架的很多价值,因为在这个过程中,人们无法访问这些绑定框架非常有趣的特性。我可以看到的唯一积极的补充是对日志记录消息打印对象的延迟创建。



SLF4J是IMHO肯定不是许多世界的最好的,它是一个最小的共同分母,对于正确的软件工程,最小值低。另一方面,现有的日志框架已经过度设计,并且经常缺少竞争对手提供的关键特性。



如果需要集成日志框架,我会看到两个选项真实实用价值:i)选择您最喜欢的日志框架,并将所有代码转换为此框架或ii)创建自己的框架(这很容易,只花了我几个小时)。



我的2美分。我没有问题的人有不同的意见。

解决方案

如果我理解正确,你正在寻找一种方法来自定义在哪个级别特定类应该记录?首先,SLF4J只是一个外观,它只重定向到一个选择的日志库(它也可以< - c $ c> java.util.logging )提供一致的API。



与SLF4J一样,您需要 true 日志框架,如回退 Log4J 。每个框架都提供了一些方法来配置日志记录级别,通常使用某种配置文件。请参阅:如何配置logback以跳过来自org.package。*的日志消息,所有级别都低于WARN?


I am considering using SLF4j to integrate multiple logging frameworks.

The java.util.logging.Logger class has a nice method called setLevel(Level newLevel). It enables logging configuration at a class level, which helps creating readable and lean traces.

I could not find the equivalent in the SLF4J framework. Is there any? The SLF4J Logger interface does not offer such a method. I have seen the other questions on StackOverflow and I have read the SL4F doc, but I could not come to a definitive conclusion.

If SLF4J does not allow the fine-tuning I am looking for, then what is the real benefit of SLF4J? It seems to strip the interesting features of binding frameworks into a most common weak and useless denominator...

If so, why shouldn't I convert all my code to my favorite Logging framework instead of going for SLF4J?

EDIT:

Ok, may be I am selfish in complaining about SLF4J not answering my hopes here. Yet, I still don't see much value in using SLF4j to integrate logging frameworks, because in the process, one looses access to very interesting features of those binding frameworks. The only positive addition I can see is the deferred creation of objects for log record message printing.

SLF4J is IMHO surely not a best of many worlds, it is a minimal common denominator and that minimal is too low for proper software engineering. On the other side, existing logging frameworks are quite over-engineered and often miss key features offered by competitors.

If one needs to integrate logging frameworks, I see two options with real practical value: i) Pick your favorite logging framework and convert all your code to this framework or ii) Create your own framework (it is dead easy, it only took me a couple of hours).

My 2 cents. I have no issue with people having a different opinion. Just stating mine from my practical experience.

解决方案

If I understand correctly, you are looking for a way to customize at which level particular classes should be logging? First of all, SLF4J is just a facade, it only redirects to a chosen logging library (it could also be java.util.logging) providing consistent API.

So along with SLF4J you need true logging framework like Logback or Log4J. Each of these frameworks provide some way to configure logging levels on per-logger basis, typically using some sort of configuration file. See this: How to configure logback to skip logging messages from org.package.* with all levels below WARN? for instance.

这篇关于SLF4J调试级配置+ Logging框架集成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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