# 实时调试
# 开启日志打印
td_enableLog(1);
# 使用 DebugConsumer
在SDK接入过程中,您可以通过使用TE的Debug功能,进行实时调试。使用Debug功能需要如下两步操作:
- 使用DebugConsumer
- 打包 .a 文件,包含 debugConsumer 的功能,
CMakeLists.txt
修改示例如下:
# Debug Library: debug consumer
if(WIN32)
add_compile_definitions(USE_WIN)
set(CMAKE_C_FLAGS "-std=c99 -pedantic-errors -m64")
else()
add_compile_definitions(USE_POSIX)
set(CMAKE_C_FLAGS "-std=c99")
endif()
SET(TE_LIB_NAME thinkingDataDebug)
add_library(${TE_LIB_NAME} src/thinkingdata.c src/td_json.c src/td_list.c src/td_util.c src/td_debug_consumer.c src/td_http_client.c)
if(WIN32)
add_compile_definitions(BUILDING_LIBCURL)
include_directories(thirdparty/pcre/include thirdparty/curl/include)
link_directories(thirdparty/pcre/lib thirdparty/curl/lib)
target_link_libraries(${TE_LIB_NAME} pcre_x64 libcurl)
else()
target_link_libraries(${TE_LIB_NAME} curl)
endif()
- 以下使用DebugConsumer的示例代码:
struct TDAnalytics* ta = NULL;
struct TDConsumer* consumer = NULL;
/*
* DebugConsumer:数据逐条上报。当出现问题时会以日志和异常的方式提示用户;不建议在线上环境使用
*/
TDConfig *config = td_init_config();
// debug_mode,0入库,否则不入库
TD_ASSERT(TD_OK == td_add_int("debug_mode", 0, config));
// TE 后台测试设备的id: 123456789
TD_ASSERT(TD_OK == td_add_string("device_id", "123456789", strlen("123456789"), config));
// 配置appid和url
char* appid = "APPID";
char* serverURL = "SERVER_URL";
TD_ASSERT(TD_OK == td_add_string("push_url", serverURL, strlen(serverURL), config));
TD_ASSERT(TD_OK == td_add_string("appid", appid, strlen(appid), config));
//生成SDK实例
if (TD_OK != td_init_consumer(&consumer, config)) {
fprintf(stderr, "Failed to initialize the consumer.");
return 1;
}
td_free_properties(config);
if (TD_OK != td_init(consumer, &ta)) {
fprintf(stderr, "Failed to initialize the SDK.");
return 1;
}
// 生成自定义属性
TDProperties *properties = td_init_properties();
// 添加设备ID属性,设备ID值为td_device_id
TD_ASSERT(TD_OK == td_add_string("#device_id", "td_device_id", strlen("td_device_id"), properties));
//上报带有自定义属性的事件数据,同样account_id 和 distinct_id 必须至少设置其中一个
TD_ASSERT(TD_OK == td_track("account_id", "distinct_id", "test", properties, ta));
td_free_properties(properties);
- TE后台添加Debug设备
为了避免 Debug 模式在生产环境上线,规定只有指定的设备才能开启 Debug 模式。只有在客户端开启了 Debug 模式,并且设备 ID 在 TE 后台的"埋点管理"页的"Debug 数据"板块中配置了的设备才能开启 Debug 模式。
Debug 模式可能会影响数据采集质量和 App 的稳定性,只用于集成阶段数据验证,不要在线上环境使用。