您的位置:首页 > 移动开发 > Android开发

Android浏览器插件开发-Log

2014-01-21 20:13 369 查看
2011-08-24 11:33 1876人阅读 评论(1) 收藏 举报

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

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

[cpp] view
plaincopy

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的定义如下

[plain] view
plaincopy

ANPLogInterfaceV0 gLogI;

ANPLogInterfaceV0的定义如下(Android_npapi.h)

[cpp] view
plaincopy

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)

[cpp] view
plaincopy

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的调用关系如下

[plain] view
plaincopy

LOG_PRI_VA@Log.h

android_vprintLog@Log.h

__android_log_vprint@Log.h

__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

writev@uio.c

注:

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

2. android系统据我所知,只有如下log会受到是否打开DEBUG的影响
LOGV* LOG_FATAL*
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: