Java logger that automatically determines caller's class name

后端 未结 21 820
礼貌的吻别
礼貌的吻别 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:09

    A good alternative is to use (one of) the lombok logs annotations : https://projectlombok.org/features/Log.html

    It generate the corresponding log statement with the current class.

提交回复
热议问题