android 浏览器插件开发 - Log

转载请注明出处:http://blog.csdn.net/awebkit


    android中的插件开发中的示例代码已经给我们说明了如何打log,参看示例代码main.cpp

    for (int i = 0; i < argc; i++) {
        if (!strcmp(argn[i], "DrawingModel")) {
            if (!strcmp(argv[i], "Bitmap")) {
                model = kBitmap_ANPDrawingModel;
            }   
            else if (!strcmp(argv[i], "Surface")) {
               model = kSurface_ANPDrawingModel;
            }   
            gLogI.log(kDebug_ANPLogType, "------ %p DrawingModel is %d", instance, model);
            break;
        }   
    }   
    我们可以使用gLogI.log打印调试信息。

    gLogI的定义如下

ANPLogInterfaceV0           gLogI;

     ANPLogInterfaceV0的定义如下(Android_npapi.h)

struct ANPLogInterfaceV0 : ANPInterface {
    /** dumps printf messages to the log file
        e.g. interface->log(instance, kWarning_ANPLogType, "value is %d", value);
     */
    void (*log)(ANPLogType, const char format[], ...);
};
       该结构的赋值如下(ANPLogInterface.cpp)
static void anp_log(ANPLogType logType, const char format[], ...) {
    va_list args;
    va_start(args, format);

    android_LogPriority priority;
    switch (logType) {
        case kError_ANPLogType:
            priority = ANDROID_LOG_ERROR;
            break;
        case kWarning_ANPLogType:
            priority = ANDROID_LOG_WARN;
            break;
        case kDebug_ANPLogType:
            priority = ANDROID_LOG_DEBUG;
            break;
        default:
            priority = ANDROID_LOG_UNKNOWN;
            break;
    }
    LOG_PRI_VA(priority, "plugin", format, args);

    va_end(args);
}

void ANPLogInterfaceV0_Init(ANPInterface* value) {
    ANPLogInterfaceV0* i = reinterpret_cast<ANPLogInterfaceV0*>(value);

    i->log = anp_log;
}
    而LOG_PRI_VA的调用关系如下 

[email protected]
[email protected]
 [email protected]
__android_log_write@logd_write.c
write_to_log@logd_write.c
__write_to_log_init@logd_write.c
__write_to_log_kernel@logd_write.c
[email protected]


    注:

    1. 插件的打印信息的channel为plugin

    2. android系统据我所知,只有如下log会受到是否打开DEBUG的影响

         LOGV*  LOG_FATAL*

你可能感兴趣的:(android,浏览器,struct,list,File)