Logback usage and printing lists

I am starting using logback and I want to know if there are better ways of doing something. I have this code: public class ClassA { private List l; private Logger logger; public ClassA(){ this.logger = LoggerFactory.getLogger(this.getClass().getName()); } .... public List method() { this.logger.debug("method()"); List 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; } I have some doubts so far: - Every class will have a `this.logger = LoggerFactory.getLogger(this.getClass().getName());` to create a logger. - Every method will have a `this.logger.debug("method()");` to know when a method is called. That doesn't look good. Is there a way to solve it? Also I want to print a list in the .log in this line: `this.logger.debug("names: {}", xxxxx);` the xxxxx should be replaced with something to print the list. An anonymous class? Thanks for reading!
The first question is a textbook case for en.wikipedia.org/wiki/Aspect-oriented_programming, but I'm not familiar enough with it myself to write an actual answer.

以上就是Logback usage and printing lists的详细内容,更多请关注web前端其它相关文章!

赞(0) 打赏
未经允许不得转载:web前端首页 » JavaScript 答疑

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

前端开发相关广告投放 更专业 更精准