Java logger that automatically determines caller's class name

后端 未结 21 722
礼貌的吻别
礼貌的吻别 2020-12-07 17:53
public static Logger getLogger() {
    final Throwable t = new Throwable();
    final StackTraceElement methodCaller = t.getStackTrace()[1];
    final Logger logger          


        
21条回答
  •  醉梦人生
    2020-12-07 18:34

    This mechanism puts in a lot of extra effort at runtime.

    If you use Eclipse as your IDE, consider using Log4e. This handy plugin will generate logger declarations for you using your favourite logging framework. A fraction more effort at coding time, but much less work at runtime.

提交回复
热议问题