투케이2K

481. (Android) [JNI] android_log_print 사용해 디버깅 로그 (debug log) 출력 방법 본문

Android

481. (Android) [JNI] android_log_print 사용해 디버깅 로그 (debug log) 출력 방법

투케이2K 2023. 2. 14. 20:42
반응형

[개발 환경 설정]

개발 툴 : AndroidStudio

 

[소스 코드]

// -----------------------------------------------------------------------------------------
// TODO [include 파일 정의 실시]
#include <jni.h>
#include <android/log.h>
#include <string>
// -----------------------------------------------------------------------------------------





// -----------------------------------------------------------------------------------------
// TODO [기존 : 결과 반환 소스 코드 작성 실시]
// [기본 경로 [패키지 및 클래스 명칭] : Java_com_example_nativelib_NativeLib_]
// [커스텀 설정 명칭] : testMain]
extern "C" JNIEXPORT jstring JNICALL
Java_com_example_nativelib_NativeLib_testMain(
        JNIEnv* env,
        jobject,

        jint num1, // [인풋 값 : int]
        jint num2 // [인풋 값 : int]
) {

    // [string 형태로 변경]
    std::string result = std::to_string(num1 + num2);

    // [로그 출력 실시]
    __android_log_print(ANDROID_LOG_VERBOSE, "LOG [V]", "DATA :: %s", result.c_str());
    __android_log_print(ANDROID_LOG_ERROR, "LOG [E]", "DATA :: %s", result.c_str());
    __android_log_print(ANDROID_LOG_WARN, "LOG [W]", "DATA :: %s", result.c_str());
    __android_log_print(ANDROID_LOG_DEBUG, "LOG [D]", "DATA :: %s", result.c_str());
    __android_log_print(ANDROID_LOG_INFO, "LOG [I]", "DATA :: %s", result.c_str());

    // [리턴 반환 실시]
    return env->NewStringUTF(result.c_str());
}
// -----------------------------------------------------------------------------------------
 

[결과 출력]

 

V/LOG [V]: DATA :: 30
E/LOG [E]: DATA :: 30
W/LOG [W]: DATA :: 30
D/LOG [D]: DATA :: 30
I/LOG [I]: DATA :: 30

 

반응형
Comments