Java source refactoring of 7000 references

前端 未结 12 1131
醉梦人生
醉梦人生 2020-12-25 13:05

I need to change the signature of a method used all over the codebase.

Specifically, the method void log(String) will take two additional arguments (

12条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-25 13:35

    If the class and method name are required for "where did this log come from?" type data, then another option is to print out a stack trace in your log method. E.g.

    public void log(String text)
    {
       StringWriter sw = new StringWriter();
       PrintWriter pw = new PrintWriter(sw, true);
       new Throwable.printStackTrace(pw);
       pw.flush();
       sw.flush();
       String stackTraceAsLog = sw.toString();
       //do something with text and stackTraceAsLog
    }
    

提交回复
热议问题