Java 日志框架中的最新选项是什么?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2533614/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
What are the latest options in Java logging frameworks?
提问by sanity
This question gets asked periodically, but I've long felt that existing Java logging frameworks were overcomplicated and over-engineered, and I want to see what's new.
这个问题会定期被问到,但我一直觉得现有的 Java 日志框架过于复杂和过度设计,我想看看有什么新东西。
I have a more critical issue on my current project as we've standardized on JSON as our human-readable data encoding, and most logging frameworks I've seen require XML. I would really rather avoid using JSON for 95% of my apps configuration, and XML for the rest just because of the logging framework (truth be told, I hate XML used for anything other than text markup, its original intended purpose).
我目前的项目有一个更关键的问题,因为我们已经将 JSON 标准化为我们的人类可读数据编码,而且我见过的大多数日志框架都需要 XML。我真的宁愿避免将 JSON 用于我的应用程序配置的 95%,而仅仅因为日志记录框架而将 XML 用于其余部分(说实话,我讨厌将 XML 用于文本标记以外的任何其他用途,这是其最初的预期目的)。
Are there any hot new Java logging frameworks that are actively maintained, reasonably powerful, have a maven repo, can be reconfigured without restarting your app, and don't tie you to XML?
是否有任何热门的新 Java 日志框架,它们得到积极维护、相当强大、具有 maven 存储库、无需重新启动应用程序即可重新配置,并且不会将您束缚在 XML 上?
回答by Pascal Thivent
You have 3 options:
您有 3 个选择:
Now, let's see how they meet your requirements:
现在,让我们看看它们如何满足您的要求:
- actively maintained
- reasonably powerful
- have a maven repo
- can be reconfigured without restarting your app
- don't tie you to XML
- 积极维护
- 相当强大
- 有一个 Maven 仓库
- 无需重启应用即可重新配置
- 不要把你绑在 XML 上
log4j:
log4j:
java.util.logging(JUL):
java.util.logging(七月):
- I'd say Yes -
- at your discretion-
- N/A -
- Yes (via JMX or
LogManager#readConfiguration()- - Yes (using properties files)
- 我会说是的 -
- 由您自行决定-
- 不适用 -
- 是(通过 JMX 或
LogManager#readConfiguration()- - 是(使用属性文件)
Logback:
登录:
- Yes -
- Yes -
- Yes -
- Yes, via JMXor autoScan-
- Configuration files in XML or Groovy
- 是的 -
- 是的 -
- 是的 -
- 是的,通过JMX或autoScan-
- XML 或 Groovy 中的配置文件
It looks like you'll have to make some concessions (or find a framework I'm not aware of). I would go for Logback, this is where things happen now.
看起来你必须做出一些让步(或者找到一个我不知道的框架)。我会去Logback,这就是现在发生的事情。
回答by duffymo
SLF4Jis the latest and greatest, as far as I know.
据我所知,SLF4J是最新最好的。
Surely the XML required to configure log4j couldn't be considered oppressive. You might be objecting to XML config in general, but even that's changing. Spring gives the option of using XML or annotations, as do most other frameworks. I think objecting to XML anything other than markup is going too far. Should Ant and NANT shut down because they chose XML? I think not.
当然,配置 log4j 所需的 XML 不能被认为是压迫性的。一般而言,您可能会反对 XML 配置,但即便如此,这种情况也在发生变化。Spring 提供了使用 XML 或注释的选项,大多数其他框架也是如此。我认为反对 XML 标记以外的任何东西都太过分了。Ant 和 NANT 是否应该因为他们选择 XML 而关闭?我想不是。
回答by Omry Yadan
回答by Dennis G.
You might want to look into our Java logging tool SmartInspect(it's commercial). SmartInspect is actively maintained, can be configured with two lines of code and supports configuration files that just contain name = value pairs (no XML :)). SmartInspect can also automatically reload configurations files on-the-fly when they are changed - a useful feature for live configuration changes and production systems. SmartInspect also comes with a graphical log analysis and monitoring tool that you might find useful:
您可能想查看我们的 Java 日志工具SmartInspect(它是商业的)。SmartInspect 是主动维护的,可以用两行代码进行配置,并支持仅包含名称 = 值对(无 XML :))的配置文件。SmartInspect 还可以在更改时自动即时重新加载配置文件 - 这是实时配置更改和生产系统的有用功能。SmartInspect 还附带一个图形日志分析和监控工具,您可能会发现它很有用:

(source: gurock.com)

(来源:gurock.com)

