在java日志框架场景中找到一种方法[英] Find a way in the java logging frameworks scene

本文是小编为大家收集整理的关于在java日志框架场景中找到一种方法的处理/解决方法,可以参考本文帮助大家快速定位并解决问题,中文翻译不准确的可切换到English标签页查看源文。

问题描述

Java有很多框架/API可以帮助您在应用程序中登录:

  1. java api具有java.util.logging包.
  2. apache的log4j.
  3. Apache的Commons记录.
  4. slf4j(伐木立面).
  5. jlo. 还有更多...

我一直使用Log4J库,大部分时间都发现它足够了,并且当我需要更多的控制时可扩展.

有超过一个框架经验的任何人都可以分享他的经验?什么时候最好从另一个框架和应用程序体系结构的角度使用一个框架?为什么我宁愿一个呢?

谢谢

推荐答案

这个问题似乎与 354837 ..

一个简单的答案是,如果您正在写一个可能被丢弃到无法控制日志记录的应用程序中的库,则您将要进行Commons Loggge,这是其他选择之一.我个人在所有情况下都使用CL,仅仅是因为它很常见 - 我不需要记住框架之间的差异.

其他推荐答案

Commons记录是奇怪的classloading问题的来源.如果可以的话,请避免它.在开发应用程序时,我更喜欢log4j.如果您开发库/框架,并且不想执行日志记录库,请选择SLF4J.

其他推荐答案

如果它将从SLF4J开始,因为它提供了最简单的方法,可以通过在您的应用程序的阶段中包括所需的SLF- [Logging_api] .jar来切换在下面的日志记录API之间.例如 - 如果从log4j开始,您仍然必须在log4j.xml中配置圆锥记录器才能查看您的记录输出,而SLF4J则只需包括Slf4j -simple.jar.

本文地址:https://www.itbaoku.cn/post/1574941.html

问题描述

Java has a lot of frameworks / APIs that help you do logging in your application:

  1. The Java API has java.util.logging package.
  2. Apache's Log4j.
  3. Apache's Commons Logging.
  4. SLF4J (logging Facade).
  5. jLo. and many many more...

I've always used the log4j library, i found it sufficient most of the time, and extensible when i needed more control.

Anyone who had experience with more than one framework can share his experience? when is it better to use one framework over the other and from application architecture point of view? Why would i prefer one over other?

Thanks

推荐答案

This question seems identical to 354837.

The simple answer is that you'd go for Commons Logging if you're writing a library that may be dropped into applications where you have no control over the logging, one of the other choices if not. I personally use CL in all cases, simply because it's common -- I don't need to remember the differences between frameworks.

其他推荐答案

Commons Logging is source of strange classloading problems. Avoid it if you can. I prefer log4j when developing application. If you develop library/framework and you don't want to enforce logging library, choose slf4j.

其他推荐答案

If its new code i'd start with slf4j, since it provides the simplest way to switch between the underlying logging api's by just including the required slf-[logging_api].jar in the classparth of your app. For example - if you start with log4j you still have to configure a Conole logger in a log4j.xml to see your logging output, with slf4j you just include the slf4j-simple.jar.