文章出處
文章列表
調試SQLite的神器,再也不用自己去打Log了,只需簡單的幾個命令。
adb shell setprop log.tag.SQLiteLog V
adb shell setprop log.tag.SQLiteStatements V
adb shell stop
adb 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
開頭的,后接任何字符都無所謂。
文章列表
全站熱搜