Android SQLite調試

來源:互聯網
上載者:User

Android SQLite調試
調試SQLite的神器,再也不用自己去打Log了,只需簡單的幾個命令。 adb shell setprop log.tag.SQLiteLog Vadb shell setprop log.tag.SQLiteStatements Vadb shell stopadb shell start結果如下所示 V/SQLiteStatements( 4405): /data/data/[package]/databases/[db_name].db: "UPDATE [table_name] SET state=-1 WHERE note_id='7556'"想關閉Log也很簡單,把上面代碼中的V改為""就行了 說明在源碼SQLiteDebug.java中  /**     * Controls the printing of informational SQL log messages.     *     * Enable using "adb shell setprop log.tag.SQLiteLog VERBOSE".     */    public static final boolean DEBUG_SQL_LOG =            Log.isLoggable("SQLiteLog", Log.VERBOSE);     /**     * Controls the printing of SQL statements as they are executed.     *     * Enable using "adb shell setprop log.tag.SQLiteStatements VERBOSE".     */    public static final boolean DEBUG_SQL_STATEMENTS =            Log.isLoggable("SQLiteStatements", Log.VERBOSE);     /**     * Controls the printing of wall-clock time taken to execute SQL statements     * as they are executed.     *     * Enable using "adb shell setprop log.tag.SQLiteTime VERBOSE".     */    public static final boolean DEBUG_SQL_TIME =            Log.isLoggable("SQLiteTime", Log.VERBOSE);源碼中說要用VERBOSE,而我們使用V確也能起作用,看下isLoggable的實現就知道了,isLoggable是native方法,實際執行的是frameworks/base/core/jni/android_util_Log.cpp的android_util_Log_isLoggable方法,android_util_Log_isLoggable調用同一檔案內的isLoggable static jboolean isLoggable(const char* tag, jint level) {    String8 key;    key.append(LOG_NAMESPACE);    key.append(tag);     char buf[PROPERTY_VALUE_MAX];    if (property_get(key.string(), buf, "") <= 0) {        buf[0] = '\0';    }     int logLevel = toLevel(buf);    return logLevel >= 0 && level >= logLevel;}isLoggable中通過propery_get擷取我們之前設定的值,然後對擷取到的結果調用toLevel static int toLevel(const char* value){    switch (value[0]) {        case 'V': return levels.verbose;        case 'D': return levels.debug;        case 'I': return levels.info;        case 'W': return levels.warn;        case 'E': return levels.error;        case 'A': return levels.assert;        case 'S': return -1; // SUPPRESS    }    return levels.info;}toLevel只判斷了值的第一個字元,所以我們之前只設定V也可以,其實只要是V開頭的,後接任何字元都無所謂。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.