编程时候的Log记录

Log4j

采用xml配置

http://blog.csdn.net/tsyj810883979/article/details/7333400

 

另一个初学不注意的,是忘记掉加上判断isDebugEnabled() or isInfoEnabled()

The reason of that is of course simple - if you do not use isDebugEnabled() the String argument of the log.debug() has to be created. Sometimes like in this example the log statements are "hidden" inside a bean - and maybe you don't think about how often the method will be called afterwards.

http://java-mistakes.blogspot.com/2011/12/not-using-isdebugenabled-or.html

 

在eclipse中使用时,log4j.xml需要配置在src/main/resources位置

http://stackoverflow.com/questions/20147433/log4j-xml-warn-no-appenders-could-be-found-for-logger

同时,配合maven使用时,为了能够给编译到target 目录中,需要在pom.xml中配置maven 的maven-resources-plugin和resource的值。

 

使用libthrift-0.9.0.jar包时,默认引入的是slf4j的1.5.8版本,要是只是想搭一个初步的demo时,会报Exception,导致程序没法继续执行,这是由于slf4j只是作为一个接口性质,真正的log实现依赖于log4j或者logback

如果手动在pom文件中指定为slf4j-api-1.6.2.jar

则不会影响程序运行,这时候default使用了nop logger,如下

SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.

 

posted on 2015-01-14 21:37  majia1949  阅读(208)  评论(0编辑  收藏  举报

导航