menu
Is this helpful?

# 디버깅

SDK로 데이터 액세스를 구현하는 중에, IDE 컨트롤러의 로그나 TE의 Debug 기능을 사용하여 디버깅할 수 있습니다.

디버그 기능은 다음의 2단계로 이용할 수 있습니다.

# 로그 기록

td_enableLog(1);

# 1. DebugConsumer 사용

  • 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, "소비자 초기화에 실패했습니다.");
    return 1;
}
td_free_properties(config);
if (TD_OK != td_init(consumer, &ta)) {
    fprintf(stderr, "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);

Debug 모드는 데이터 수집의 질과 앱의 안정성에 영향을 미칩니다. 따라서 데이터 검증을 위해서만 사용해 주세요.