LoggerFactory.getLogger(ClassName.class) vs LoggerFactory.getLogger(this.getClass().getName())

前端 未结 7 859
小蘑菇
小蘑菇 2021-02-04 00:48

I\'m trying to improve my optimization skills in Java. In order to achieve that, I\'ve got an old program I made and I\'m trying my best to make it better. In this program I\'m

7条回答
  •  天命终不由人
    2021-02-04 01:20

    Use this

    private final Logger logger = LoggerFactory.getLogger(this.getClass()); 
    
    }
    // logic
    try
    {
    // todo
    }
    
    catch (NullPointerException e) {
            logger.error("Error:-" + e.getMessage());
              return ResponseUtil.errorResponse(e.getMessage());
            }
    
            catch (Exception e) {
                logger.error("Error:-" + e.getMessage());
                return ResponseUtil.errorResponse(e.getMessage());
            }
    

提交回复
热议问题