我开始使用logback,我想知道是否有更好的方法做某事。 我有这样的代码:Logback的使用和打印列表
public class ClassA {
private List<String> l;
private Logger logger;
public ClassA(){
this.logger = LoggerFactory.getLogger(this.getClass().getName());
}
....
public List<String> method() {
this.logger.debug("method()");
List<String> names;
try {
names = otherClass.getNames();
} catch (Exception e) {
String msg = "Error getting names";
this.logger.error(msg);
throw new ClassAexception(msg, e);
}
this.logger.debug("names: {}", xxxxx);
return names;
}
我有些疑惑至今:
- 每次上课都会有
this.logger = LoggerFactory.getLogger(this.getClass().getName());
创建一个记录器。 - 每个方法都有一个
this.logger.debug("method()");
来知道何时调用方法。
这看起来不太好。有没有办法解决它?
而且我想打印一个列表中的.log在这条线:this.logger.debug("names: {}", xxxxx);
xxxxx的应该这样打印的清单来代替。一个匿名课程?
感谢您的阅读!
第一个问题是http://en.wikipedia.org/wiki/Aspect-oriented_programming的教科书案例,但我自己并不熟悉写一个实际的答案。 – 2009-06-26 19:20:50