?? 目前流行的日志方法是slf4j+log4j。
???所以我们的代码中均可以使用slf4j的接口,在代码中,请这样编写:
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
.......
public class HelloService implements Serializable {
private static final Logger log = LoggerFactory
.getLogger(HelloService.class);
private static final long serialVersionUID = 2360207348764416203L;
......
public List getList() {
......
log.debug("try to get Data ...");
log.info("Temperature set to {}. Old temperature was {}.", t, oldT);
log.error("{}, {}, {}", new Object[]{"a", 3, 4.5});
......
请不要使用System.out.print之类的方法
注意调用相应的trace, debug, info, warn, error之类的级别,以方便后续部署去掉无用的日志,也可以在需要找问题的时候打开相应的日志。
一般需要程序员看的调试信息使用debug
一般需要网络管理需要的知道的使用info
一般需要关注的是warn
如果有错误则使用error