Logging a methods's name and parameters

前端 未结 4 1474
星月不相逢
星月不相逢 2021-02-10 15:12

I\'ve been working with a company that, in this current project, has to implement a policy of writing lots of trace logging in code (JAVA) that has already been completed for so

4条回答
  •  [愿得一人]
    2021-02-10 15:27

    Go to Window->Preferences, select Java->Editor->Templates, create a new template named "logmeth" with Pattern i.e.:

    if(logger.isDebug())logger.debug("${exception_variable_name} ${return_type} "+getClass().getName()+"${enclosing_method}(${enclosing_method_arguments})"+String.format("***",${enclosing_method_arguments}));
    

    and press OK.

    In java Editor write logmeth and press Strg+space+space and Enter and Eclipse will write i.e.:

    if(logger.isDebug())logger.debug("e boolean hasFuture(man, woman)"
                + String.format("***", man, woman));
    

    Eclipse is so cool.

提交回复
热议问题