[Android]Android 直接打開log的一種方法

針對Apk log內部控制方式是經過Log.isLoggable來控制的狀況java

Example: adb shell setprop log.tag.Finsky VERBOSEandroid

通常code是這樣寫的: import android.util.Log;shell

public class FinskyLog { public static final boolean DEBUG = Log.isLoggable(TAG, 2); private static String TAG = "Finsky";app

Log.isLoggable的實現: Native層處理文件:android_util_Log.cpp (\frameworks\base\core\jni)google

Java 定義在Log.java \frameworks\base\core\java\android\util public static native boolean isLoggable(String tag, int level); 很是有助於無source code apk的debug,好比google apkdebug

struct levels_t { jint verbose; jint debug; jint info; jint warn; jint error; jint assert; }; static levels_t levels;code

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; }get

static jboolean isLoggable(const char* tag, jint level) { String8 key; key.append(LOG_NAMESPACE); key.append(tag);string

char buf[PROPERTY_VALUE_MAX];
if (property_get(key.string(), buf, "") <= 0) {
    buf[0] = '\0';
}

int logLevel = toLevel(buf);
return logLevel >= 0 && level >= logLevel;

}it

相關文章
相關標籤/搜索