作者:基基蛋 | 来源:互联网 | 2023-10-13 11:24
日志记录显示具体位置方法类名。privatestaticStringbuildMessage(Stringformat,Objectargs){Stringmsg(argsn
日志 记录显示 具体位置方法类名。
private static String buildMessage(String format, Object... args) {String msg = (args == null) ? format : String.format(Locale.US, format, args);StackTraceElement[] trace = new Throwable().fillInStackTrace().getStackTrace();String caller = "";// Walk up the stack looking for the first caller outside of VolleyLog.// It will be at least two frames up, so start there.for (int i = 2; i clazz = trace[i].getClass();if (!clazz.equals(VolleyLog.class)) {String callingClass = trace[i].getClassName();callingClass = callingClass.substring(callingClass.lastIndexOf('.') + 1);callingClass = callingClass.substring(callingClass.lastIndexOf('$') + 1);caller = callingClass + "." + trace[i].getMethodName();break;}}return String.format(Locale.US, "[%d] %s: %s",Thread.currentThread().getId(), caller, msg);}