slf4j 与 log4j比较

15 down vote accepted

You can think of slf4j as a big "interface" that needs an implementation. So, just using slf4j standalone will not get you any logging (aside from using slf4j-simple, which is a bundled mini implementation that can only log to console).

So, what can you use as an implementation? log4j is one example. Why would you want to use slf4j then? Because you can use this one interface and then swap implementations if needed.

What are the available backends that can be used?

  • log4j
  • java.util.logging
  • commons logging
  • logback

I'd suggest using Logback. It's a better log4j.

 
 
slf4j 与 log4j比较
2010-02-08 16:40
log4j不用说,比起jdk和common-logger还是有优势的。commons-logger我认为都不是鸡肋,完全没有使用的必要,要不你就使用log4j要不就直接使用jdk。
下面对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。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值