Android “是什么意思?”;wtf“;在安卓截击中?

Android “是什么意思?”;wtf“;在安卓截击中?,android,android-volley,android-log,Android,Android Volley,Android Log,我遇到了这种方法 public static void wtf(String format, Object... args) { Log.wtf(TAG, buildMessage(format, args)); } public static int wtf(String tag, String msg, Throwable tr) { throw new RuntimeException("Stub!"); } 当我仔细查看安卓截击时

我遇到了这种方法

 public static void wtf(String format, Object... args) {
        Log.wtf(TAG, buildMessage(format, args));
    }



public static int wtf(String tag, String msg, Throwable tr) {
        throw new RuntimeException("Stub!");
    }
当我仔细查看
安卓截击
时,
库开发人员使用此方法记录
截击
中的错误
,但是除了通常的方法之外,这还有其他意义吗? 我不确定程序员是否应该有这样的命名约定?

引用:


多么可怕的失败:报告一个永远不会发生的情况。 错误将始终与调用堆栈一起记录在断言级别


很明显,
WTF
代表了
多么可怕的失败
。你可以从邪恶博士的书中拿出一页,这样说:;)


用于检测类似日志的:

package com.android.volley;

import android.os.SystemClock;
import android.util.Log;

import java.util.ArrayList;
import java.util.List;
import java.util.Locale;

/** Logging helper class. */
public class VolleyLog {
    public static String TAG = "Volley";

    public static boolean DEBUG = Log.isLoggable(TAG, Log.VERBOSE);

    /**
     * Customize the log tag for your application, so that other apps
     * using Volley don't mix their logs with yours.
     * <br />
     * Enable the log property for your tag before starting your app:
     * <br />
     * {@code adb shell setprop log.tag.&lt;tag&gt;}
     */
    public static void setTag(String tag) {
        d("Changing log tag to %s", tag);
        TAG = tag;

        // Reinitialize the DEBUG "constant"
        DEBUG = Log.isLoggable(TAG, Log.VERBOSE);
    }

    public static void v(String format, Object... args) {
        if (DEBUG) {
            Log.v(TAG, buildMessage(format, args));
        }
    }

    public static void d(String format, Object... args) {
        Log.d(TAG, buildMessage(format, args));
    }

    public static void e(String format, Object... args) {
        Log.e(TAG, buildMessage(format, args));
    }

    public static void e(Throwable tr, String format, Object... args) {
        Log.e(TAG, buildMessage(format, args), tr);
    }

    public static void wtf(String format, Object... args) {
        Log.wtf(TAG, buildMessage(format, args));
    }

    public static void wtf(Throwable tr, String format, Object... args) {
        Log.wtf(TAG, buildMessage(format, args), tr);
    }

    /**
     * Formats the caller's provided message and prepends useful info like
     * calling thread ID and method name.
     */
    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 = "<unknown>";
        // 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 < trace.length; i++) {
            Class<?> 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);
    }

    /**
     * A simple event log with records containing a name, thread ID, and timestamp.
     */
    static class MarkerLog {
        public static final boolean ENABLED = VolleyLog.DEBUG;

        /** Minimum duration from first marker to last in an marker log to warrant logging. */
        private static final long MIN_DURATION_FOR_LOGGING_MS = 0;

        private static class Marker {
            public final String name;
            public final long thread;
            public final long time;

            public Marker(String name, long thread, long time) {
                this.name = name;
                this.thread = thread;
                this.time = time;
            }
        }

        private final List<Marker> mMarkers = new ArrayList<Marker>();
        private boolean mFinished = false;

        /** Adds a marker to this log with the specified name. */
        public synchronized void add(String name, long threadId) {
            if (mFinished) {
                throw new IllegalStateException("Marker added to finished log");
            }

            mMarkers.add(new Marker(name, threadId, SystemClock.elapsedRealtime()));
        }

        /**
         * Closes the log, dumping it to logcat if the time difference between
         * the first and last markers is greater than {@link #MIN_DURATION_FOR_LOGGING_MS}.
         * @param header Header string to print above the marker log.
         */
        public synchronized void finish(String header) {
            mFinished = true;

            long duration = getTotalDuration();
            if (duration <= MIN_DURATION_FOR_LOGGING_MS) {
                return;
            }

            long prevTime = mMarkers.get(0).time;
            d("(%-4d ms) %s", duration, header);
            for (Marker marker : mMarkers) {
                long thisTime = marker.time;
                d("(+%-4d) [%2d] %s", (thisTime - prevTime), marker.thread, marker.name);
                prevTime = thisTime;
            }
        }

        @Override
        protected void finalize() throws Throwable {
            // Catch requests that have been collected (and hence end-of-lifed)
            // but had no debugging output printed for them.
            if (!mFinished) {
                finish("Request on the loose");
                e("Marker log finalized without finish() - uncaught exit point for request");
            }
        }

        /** Returns the time difference between the first and last events in this log. */
        private long getTotalDuration() {
            if (mMarkers.size() == 0) {
                return 0;
            }

            long first = mMarkers.get(0).time;
            long last = mMarkers.get(mMarkers.size() - 1).time;
            return last - first;
        }
    }
}
package com.android.volley;
导入android.os.SystemClock;
导入android.util.Log;
导入java.util.ArrayList;
导入java.util.List;
导入java.util.Locale;
/**日志助手类*/
公开课截击记录{
公共静态字符串TAG=“Volley”;
publicstaticbooleandebug=Log.isLoggable(标记,Log.VERBOSE);
/**
*自定义应用程序的日志标记,以便其他应用程序
*使用截击,不要把他们的日志和你的日志混在一起。
*
*在启动应用程序之前,为标记启用日志属性: *
*{@code adb shell setprop log.tag.tag} */ 公共静态void setTag(字符串标记){ d(“将日志标记更改为%s”,标记); 标签=标签; //重新初始化调试“常量” DEBUG=Log.isLoggable(标记,Log.VERBOSE); } 公共静态void v(字符串格式、对象…参数){ 如果(调试){ Log.v(标记,buildMessage(格式,args)); } } 公共静态void d(字符串格式、对象…参数){ Log.d(标记,buildMessage(格式,args)); } 公共静态void e(字符串格式、对象…参数){ Log.e(标记,buildMessage(格式,args)); } 公共静态void e(可丢弃的tr、字符串格式、对象…args){ Log.e(标签、buildMessage(格式、args)、tr); } 公共静态void wtf(字符串格式、对象…参数){ wtf(标记,buildMessage(格式,args)); } 公共静态void wtf(可丢弃的tr、字符串格式、对象…args){ Log.wtf(标记,buildMessage(格式,args),tr); } /** *格式化调用者提供的消息并预先添加有用的信息,如 *调用线程ID和方法名。 */ 私有静态字符串构建消息(字符串格式、对象…参数){ 字符串msg=(args==null)?格式:String.format(Locale.US,format,args); StackTraceElement[]trace=new Throwable().fillInStackTrace().getStackTrace(); 字符串调用者=”; //在堆栈中查找凌空记录之外的第一个调用方。 //这将是至少两帧了,所以从那里开始。 对于(int i=2;iif(What a可怕的失败它意味着“What a可怕的失败”…我希望他们能用一个更专业、更具G级的名字来重新命名这个电话。众所周知,WTF代表着其他东西(不管你怎么说)。我理解了非编程的含义,现在很清楚了:)。