{"rsdb":{"rid":"386201","subhead":"","postdate":"0","aid":"269184","fid":"98","uid":"1","topic":"1","content":"
\n

\u672c\u6587\u5fae\u4fe1\u516c\u4f17\u53f7\u300cAndroidTraveler\u300d\u9996\u53d1\u3002<\/strong><\/p> \n

\u80cc\u666f<\/h3> \n

\u5728\u5f00\u53d1\u8fc7\u7a0b\u4e2d\uff0c\u8c03\u8bd5\u662f\u5fc5\u4e0d\u53ef\u5c11\u7684\u4e00\u9879\u5de5\u4f5c\u3002<\/p> \n

\u5f53\u6211\u4eec\u8981\u786e\u5b9a\u9879\u76ee\u7684\u903b\u8f91\u65f6\uff0c\u5f53\u6211\u4eec\u8981\u4e86\u89e3\u754c\u9762\u7684\u751f\u547d\u5468\u671f\u65f6\uff0c\u5f53\u6211\u4eec\u53d1\u73b0\u65b0\u5199\u7684\u903b\u8f91\u4e0e\u671f\u671b\u6548\u679c\u4e0d\u4e00\u81f4\u65f6\uff0c\u5f53\u6211\u4eec\u89c9\u5f97\u6570\u636e\u6709\u95ee\u9898\u65f6......<\/p> \n

\u800c\u8c03\u8bd5\u6709\u4e24\u79cd\u65b9\u5f0f\uff1a<\/p> \n

\u7b2c\u4e00\u79cd\u5c31\u662f\u4f7f\u7528 debug \u6a21\u5f0f\u8fd0\u884c APP\uff0c\u7136\u540e\u901a\u8fc7\u65ad\u70b9\u8ba9\u7a0b\u5e8f\u8fd0\u884c\u5230\u6307\u5b9a\u4f4d\u7f6e\u8fdb\u884c\u5206\u6790\u3002<\/p> \n

\u7b2c\u4e8c\u79cd\u5c31\u662f\u6253\u65e5\u5fd7\u7684\u65b9\u5f0f\uff0c\u901a\u8fc7\u89c2\u5bdf\u8f93\u51fa\u6765\u786e\u5b9a\u7a0b\u5e8f\u662f\u5426\u8fd0\u884c\u5230\u8be5\u4f4d\u7f6e\u4ee5\u53ca\u6b64\u65f6\u7684\u6570\u636e\u3002<\/p> \n

\u672c\u7bc7\u6587\u7ae0\u4e3b\u8981\u805a\u7126\u5728\u7b2c\u4e8c\u79cd\u65b9\u5f0f\u4e0a\u9762\u3002<\/p> \n

\u5728 Android \u91cc\u9762\uff0c\u6253\u65e5\u5fd7\u4f7f\u7528\u7684\u7cfb\u7edf API \u662f Log\uff0c\u4f60\u4ee5\u4e3a\u76f4\u63a5\u4f7f\u7528\u5c31\u5b8c\u4e86\u5417\uff1f<\/p> \n

\u5c01\u88c5<\/h3> \n

\u5047\u8bbe\u4f60\u5728\u9700\u8981\u6253\u5370\u65e5\u5fd7\u7684\u5730\u65b9\u76f4\u63a5\u4f7f\u7528\u7cfb\u7edf\u7684 API\uff0c\u90a3\u4e48\u5f53\u9047\u5230\u4e0b\u9762\u60c5\u51b5\u65f6\uff0c\u4f1a\u300c\u7275\u4e00\u53d1\u800c\u52a8\u5168\u8eab\u300d\u3002<\/p> \n

\u573a\u666f\u4e00\uff1a\u5982\u679c\u6211\u6253\u5370\u65e5\u5fd7\u8981\u7528\u4e09\u65b9\u5e93\u7684\u65e5\u5fd7 API\uff0c\u90a3\u4e48\u6211\u8981\u67e5\u627e\u9879\u76ee\u6240\u6709\u4f7f\u7528\u4f4d\u7f6e\uff0c\u5e76\u4e00\u4e00\u66ff\u6362\u3002<\/p> \n

\u573a\u666f\u4e8c\uff1a\u5982\u679c\u6211\u5e0c\u671b\u5728\u5f00\u53d1\u73af\u5883\u4e0b\u6253\u5370\u65e5\u5fd7\uff0crelease \u73af\u5883\u4e0d\u6253\u5370\uff0c\u8fd9\u4e2a\u65f6\u5019\u6bcf\u4e2a\u4f4d\u7f6e\u90fd\u9700\u8981\u5355\u72ec\u505a\u5904\u7406\u3002<\/p> \n

\u56e0\u6b64\u6211\u4eec\u9700\u8981\u5728\u4f7f\u7528 Log \u8fdb\u884c\u65e5\u5fd7\u6253\u5370\u4e4b\u524d\uff0c\u505a\u4e00\u5c42\u5c01\u88c5\u3002<\/p> \n

\u5047\u8bbe\u6211\u4eec\u7684\u7c7b\u540d\u5b57\u4e3a ZLog\uff0c\u4ee3\u7801\u5982\u4e0b\uff1a<\/p> \n

import android.util.Log;\n\n\/**\n * Created on 2019-10-26\n *\n * @author Zengyu.Zhan\n *\/\npublic class ZLog {\n    public static int v(String tag, String msg) {\n        return Log.v(tag, msg);\n    }\n\n    public static int d(String tag, String msg) {\n        return Log.d(tag, msg);\n    }\n\n    public static int i(String tag, String msg) {\n        return Log.i(tag, msg);\n    }\n\n    public static int w(String tag, String msg) {\n        return Log.w(tag, msg);\n    }\n\n    public static int e(String tag, String msg) {\n        return Log.e(tag, msg);\n    }\n}<\/code><\/pre> \n 

\u8fd9\u6837\u5904\u7406\u4e4b\u540e\uff0c\u5bf9\u4e8e\u573a\u666f\u4e00\u548c\u573a\u666f\u4e8c\uff0c\u6211\u4eec\u9700\u8981\u4fee\u6539\u7684\u53ea\u662f ZLog \u8fd9\u4e2a\u7c7b\uff0c\u800c\u4e0d\u9700\u8981\u5230\u5177\u4f53\u4f7f\u7528 ZLog \u7684\u6240\u6709\u5730\u65b9\u53bb\u4fee\u6539\u3002<\/p> \n

\u63d0\u4f9b\u65e5\u5fd7\u6253\u5370\u63a7\u5236<\/h3> \n

\u6211\u4eec\u77e5\u9053\uff0c\u65e5\u5fd7\u6253\u5370\u53ef\u80fd\u5305\u542b\u654f\u611f\u4fe1\u606f\uff0c\u800c\u4e14\u8fc7\u591a\u7684\u65e5\u5fd7\u6253\u5370\u53ef\u80fd\u5f71\u54cd APP \u7684\u6027\u80fd\uff0c\u56e0\u6b64\u6211\u4eec\u4e00\u822c\u662f\u5728\u5f00\u53d1\u65f6\u5019\u6253\u5f00\u65e5\u5fd7\uff0c\u5728\u53d1\u5e03 APP \u4e4b\u524d\u5173\u95ed\u3002<\/p> \n

\u56e0\u6b64\u6211\u4eec\u8fd9\u8fb9\u9700\u8981\u63d0\u4f9b\u4e00\u4e2a\u6807\u5fd7\u4f4d\u6765\u63a7\u5236\u65e5\u5fd7\u7684\u6253\u5370\u4e0e\u5426\u3002<\/p> \n

import android.util.Log;\n\n\/**\n * Created on 2019-10-26\n *\n * @author Zengyu.Zhan\n *\/\npublic class ZLog {\n    private static boolean isDebugMode = false;\n    public static void setDebugMode(boolean debugMode) {\n        isDebugMode = debugMode;\n    }\n\n    public static int v(String tag, String msg) {\n        return isDebugMode ? Log.v(tag, msg) : -1;\n    }\n\n    public static int d(String tag, String msg) {\n        return isDebugMode ? Log.d(tag, msg) : -1;\n    }\n\n    public static int i(String tag, String msg) {\n        return isDebugMode ? Log.i(tag, msg) : -1;\n    }\n\n    public static int w(String tag, String msg) {\n        return isDebugMode ? Log.w(tag, msg) : -1;\n    }\n\n    public static int e(String tag, String msg) {\n        return isDebugMode ? Log.e(tag, msg) : -1;\n    }\n}<\/code><\/pre> \n 

\u9ed8\u8ba4\u662f\u4e0d\u5f00\u542f\u65e5\u5fd7\u6253\u5370\uff0c\u907f\u514d\u5f00\u53d1\u8005\u5fd8\u8bb0\u8bbe\u7f6e\u3002<\/p> \n

\u666e\u901a\u65e5\u5fd7\u548c\u5954\u6e83\u6808\u7cfb\u7edf\u65e5\u5fd7\u5728\u63a7\u5236\u53f0\u7684\u8f93\u51fa\u5bf9\u6bd4<\/h3> \n

\u73b0\u5728\u6211\u4eec\u5728 APP \u91cc\u9762\u4f7f\u7528 ZLog \u6253\u5370\u65e5\u5fd7\uff0c\u4ee3\u7801\u4e3a\uff1a<\/p> \n

ZLog.setDebugMode(true);\nZLog.e("ZLog", "just test");<\/code><\/pre> \n 

\u8f93\u51fa\u5982\u4e0b\uff1a<\/p> \n

<\/p> \n

\u6211\u4eec\u73b0\u5728\u589e\u52a0\u5982\u4e0b\u4ee3\u7801\uff1a<\/p> \n

String nullString = null;\nif (nullString.equals("null")) {\n}<\/code><\/pre> \n 

\u8fd0\u884c\u4e4b\u540e\u63a7\u5236\u53f0\u4f1a\u663e\u793a\u7a7a\u6307\u9488\u5f02\u5e38\u5954\u6e83\u6808\uff0c\u5982\u4e0b\uff1a<\/p> \n

<\/p> \n

\u53ef\u4ee5\u770b\u5230\u5954\u6e83\u6808\u4fe1\u606f\u4f1a\u663e\u793a\u5177\u4f53\u662f\u54ea\u4e2a\u6587\u4ef6\u51fa\u73b0\u4e86\u7a7a\u6307\u9488\uff0c\u4ee5\u53ca\u5177\u4f53\u54ea\u4e00\u884c\u3002\u5728\u6211\u4eec\u8fd9\u4e2a\u4f8b\u5b50\u91cc\u9762\u5c31\u662f MainActivity.java<\/a><\/strong> \u7684 24<\/strong> \u884c\u3002<\/p> \n

\u800c\u4e14\u70b9\u51fb\u84dd\u8272\u94fe\u63a5\u5149\u6807\u4f1a\u76f4\u63a5\u5b9a\u4f4d\u5230\u9519\u8bef\u4f4d\u7f6e\u3002<\/p> \n

\u5982\u679c\u6211\u4eec\u666e\u901a\u7684\u65e5\u5fd7\u4e5f\u53ef\u4ee5\u70b9\u51fb\u5c31\u8df3\u8f6c\u5230\u5bf9\u5e94\u4f4d\u7f6e\uff0c\u5bf9\u4e8e\u6211\u4eec\u5f00\u53d1\u6765\u8bf4\u6548\u7387\u662f\u6709\u5f88\u5927\u63d0\u5347\u7684\u3002<\/p> \n

<\/p> \n

ZLogHelper<\/h3> \n

\u65e2\u7136\u5954\u6e83\u6808\u91cc\u9762\u6709\u94fe\u63a5\u53ef\u4ee5\u8df3\u8f6c\uff0c\u90a3\u4e48\u6211\u4eec\u53ef\u4ee5\u901a\u8fc7\u6808\u4fe1\u606f\u6765\u83b7\u53d6\u65e5\u5fd7\u7684\u6253\u5370\u4f4d\u7f6e\u3002<\/p> \n

\u6211\u4eec\u76f4\u63a5\u4e0a\u4ee3\u7801\uff1a<\/p> \n

public class ZLogHelper {\n    private static final int CALL_STACK_INDEX = 1;\n    private static final Pattern ANONYMOUS_CLASS = Pattern.compile("(\\\\$\\\\d+)+$");\n\n    public static String wrapMessage(int stackIndex, String message) {\n        \/\/ DO NOT switch this to Thread.getCurrentThread().getStackTrace().\n        if (stackIndex < 0) {\n            stackIndex = CALL_STACK_INDEX;\n        }\n        StackTraceElement[] stackTrace = new Throwable().getStackTrace();\n        if (stackTrace.length <= stackIndex) {\n            throw new IllegalStateException(\n                    "Synthetic stacktrace didn't have enough elements: are you using proguard?");\n        }\n        String clazz = extractClassName(stackTrace[stackIndex]);\n        int lineNumber = stackTrace[stackIndex].getLineNumber();\n        message = ".(" + clazz + ".java<\/a>:" + lineNumber + ") - " + message;\n        return message;\n    }\n\n    \/**\n     * Extract the class name without any anonymous class suffixes (e.g., {@code Foo$1}\n     * becomes {@code Foo}).\n     *\/\n    private static String extractClassName(StackTraceElement element) {\n        String tag = elemen","orderid":"0","title":"Android Debug \u4e4b Log \u6700\u4f73\u5b9e\u8df5(\u4e00)","smalltitle":"","mid":"0","fname":"Android","special_id":"0","bak_id":"0","info":"0","hits":"32","pages":"3","comments":"0","posttime":"2019-11-18 11:20:40","list":"1574047240","username":"admin","author":"","copyfrom":"","copyfromurl":"","titlecolor":"","fonttype":"0","titleicon":"0","picurl":"https:\/\/www.cppentry.com\/upload_files\/","ispic":"0","yz":"1","yzer":"","yztime":"0","levels":"0","levelstime":"0","keywords":"Android<\/A> Debug<\/A> Log<\/A> \u6700\u4f73<\/A> \u5b9e\u8df5<\/A>","jumpurl":"","iframeurl":"","style":"","template":"a:3:{s:4:\"head\";s:0:\"\";s:4:\"foot\";s:0:\"\";s:8:\"bencandy\";s:0:\"\";}","target":"0","ip":"14.17.22.35","lastfid":"0","money":"0","buyuser":"","passwd":"","allowdown":"","allowview":"","editer":"","edittime":"0","begintime":"0","endtime":"0","description":"Android Debug \u4e4b Log \u6700\u4f73\u5b9e\u8df5","lastview":"1576010961","digg_num":"0","digg_time":"0","forbidcomment":"0","ifvote":"0","heart":"","htmlname":"","city_id":"0"},"page":"1"}