原文地址:http://blog.csdn.net/lifuxiangcaohui/article/details/
log4j 大家都知道,就不在多说了,重点说说slf4j;
SLF4J获得logger对象: private static final Logger logger = LoggerFactory.getLogger(Test.class); 输出日志信息: logger.debug(“debug”); LOG4J获得logger对象: public class A { private static Logger logger = Logger.getLogger(A.class); }
下面对slf4j和log4j做一下总结:
(1)大部分人在程序里面会去写logger.error(exception),其实这个时候log4j会去把这个exception tostring。真正的写法应该是logger(message.exception);而slf4j就不会使得程序员犯这个错误。 (2)log4j间接的在鼓励程序员使用string相加的写法,而slf4j就不会有这个问题。你可以使用logger.error(“{} is+serviceid”,serviceid)。 (3)使用slf4j可以方便的使用其提供的各种集体的实现的jar。(类似commons-logger) (4)从commons–logger和log4j merge非常方便,slf4j也提供了一个swing的tools来帮助大家完成这个merge。
|
发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/217256.html原文链接:https://javaforall.net
