android.util.Log#println_native()中有什么?

mid*_*ite 1 java logging android println android-source

android.util.Log源代码.

在最底层(第340行),方法中包括:

public static native int println_native(int bufID,
        int priority, String tag, String msg);
Run Code Online (Sandbox Code Playgroud)

我想println_native()或多或少喜欢它println(),只是有int bufID不同的.

但即使我得到了代码println_native(),我仍然缺乏com.android.internal.os.RuntimeInit(第19行import),以模拟android.util.Log旧的Android版本.

Roy*_*nto 6

刚刚在android源代码中进行了一些挖掘.此功能映射到

static jint android_util_Log_println_native(JNIEnv* env, jobject clazz,
    jint bufID, jint priority, jstring tagObj, jstring msgObj)
{
const char* tag = NULL;
const char* msg = NULL;

if (msgObj == NULL) {
    jniThrowNullPointerException(env, "println needs a message");
    return -1;
}

if (bufID < 0 || bufID >= LOG_ID_MAX) {
    jniThrowNullPointerException(env, "bad bufID");
    return -1;
}

if (tagObj != NULL)
    tag = env->GetStringUTFChars(tagObj, NULL);
msg = env->GetStringUTFChars(msgObj, NULL);

int res = __android_log_buf_write(bufID, (android_LogPriority)priority, tag, msg);

if (tag != NULL)
    env->ReleaseStringUTFChars(tagObj, tag);
env->ReleaseStringUTFChars(msgObj, msg);

return res;
}
Run Code Online (Sandbox Code Playgroud)

基本上,这会将参数传递给系统中的驱动程序,该驱动程序将写入Log缓冲区.日志缓冲区/dev/log在Linux内核中指向.

  • 试试这个 http://code.google.com/p/pdroid/source/browse/trunk/frameworks/base/core/jni/android_util_Log.cpp?r=57 (2认同)