Find a way in the java logging frameworks scene

你说的曾经没有我的故事 提交于 2019-12-05 19:31:21
kdgregory

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.

Logback is a rewrite of log4j. If you like log4j, you should like logback even better.

Moreover, logback is a native implementation of the SLF4J API which means that is you are using logback, then you are actually using SLF4J. Thus, if for any reason you wish to switch back to another logging framework, be it log4j or j.u.l. you can do so by replacing one jar file with another.

Whatever the official position is "log4j" is the standard logging framework.

It works well and has been around for a while. Its the most deployed logging framework used by thousands of apps and packages. Its also the logging framework most likely to appear on a developers CV.

Stick with log4j there is no good reason to try anything else.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!