How to name a slf4j logger

  1. Use logger in a non-static context:

Logger logger = LoggerFactory.getLogger(this.getClass().getName());

  1. Use logger in a static context(for example in main() method):

static Logger logger = LoggerFactory.getLogger(TheWrapperClassName.class);

Method 1 is prefered, because it has no hard-coding for class name.

static final Logger logger = Logger.getLogger(new Throwable() .getStackTrace()[0].getClassName()); maybe a solution, but may slown down the app.

posted on 2014-03-18 08:04  leechau  阅读(109)  评论(0)    收藏  举报

导航