本站首页    管理页面    写新日志    退出


«may 2026»
12
3456789
10111213141516
17181920212223
24252627282930
31


公告
暂无公告...

我的分类(专题)

日志更新

最新评论

留言板

链接


Blog信息
blog名称:
日志总数:83
评论数量:123
留言数量:0
访问次数:269536
建立时间:2006年8月17日




[Java技术]使用SLF4J
原创空间,  软件技术

lylhelin 发表于 2006/12/1 15:05:08

全称:Simple Logging Facade for Java 简单日志门面(Facade)SLF4J是为各种loging APIs提供一个简单统一的接口,从而使得最终用户能够在部署的时候配置自己希望的loging APIs实现。 Logging API实现既可以选择直接实现SLF4J接口的loging APIs如: logback、SimpleLogger。也可以通过开发相应的适配器来使用已有的API实现如Log4jLoggerAdapter、JDK14LoggerAdapter。SLF4J 不依赖任何特殊的class loader机制,实际上,SLF4J 和已有日志实现的绑定是在编译时静态执行的,具体绑定工作是通过一个jar包实现的,使用时只要把相应的jar包(只有一个)放到类路径上即可。在SLF4J发行版本中包含了几个jar包,如slf4j-nop.jar, slf4j-simple.jar, slf4j-log4j12.jar, slf4j-log4j13.jar, slf4j-jdk14.jar and slf4j-jcl.jar,Each of these jar files is hardwired at compile-time to use just one implementation, that is NOP, Simple, log4j version 1.2, log4j version 1.3, JDK 1.4 logging, and repectively JCL. SLF4J支持多个日志系统,比如NOP, Simple, log4j version 1.2, log4j version 1.3, JDK 1.4 logging, JCL and logback。 典型的使用模式: 1: import org.slf4j.Logger; 2: import org.slf4j.LoggerFactory; 3:  4: public class Wombat { 5:   6:   final Logger logger = LoggerFactory.getLogger(Wombat.class); 7:   Integer t; 8:   Integer oldT; 9:10:   public void setTemperature(Integer temparature) {11:    12:     oldT = t;        13:     t = temperature;14:15:     logger.debug("Temperature set to {}. Old temperature was {}.", t, oldT);16:17:     if(temperature.intValue() > 50) {18:       logger.info("Temperature has risen above 50 degrees.");19:     }20:   }21: }参考资源:http://www.slf4j.org/ 


阅读全文(7680) | 回复(0) | 编辑 | 精华
 



发表评论:
昵称:
密码:
主页:
标题:
验证码:  (不区分大小写,请仔细填写,输错需重写评论内容!)



站点首页 | 联系我们 | 博客注册 | 博客登陆

Sponsored By W3CHINA
W3CHINA Blog 0.8 Processed in 0.031 second(s), page refreshed 144852207 times.
《全国人大常委会关于维护互联网安全的决定》  《计算机信息网络国际联网安全保护管理办法》
苏ICP备05006046号