我開始使用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