//
// Created by #Suyghur, on 2021/10/15.
//

#include "yylog.h"

bool YYLog::is_debug = true;

void YYLog::D(JNIEnv *env, const std::string &msg) {
    if (is_debug) {
        jclass clz = env->FindClass("cn/yyxx/commsdk/core/utils/YYLog");
        if (clz == nullptr) {
            LOGE("YYLog clz is null");
            return;
        }
        const char *method_name = "d";
        const char *sig = "(Ljava/lang/String;Ljava/lang/Object;)V";
        jmethodID mid = env->GetStaticMethodID(clz, method_name, sig);
        jstring jtag = env->NewStringUTF(TAG);
        jstring jmsg = env->NewStringUTF(msg.c_str());
        env->CallStaticVoidMethod(clz, mid, jtag, jmsg);
    }
}

void YYLog::I(JNIEnv *env, const std::string &msg) {
    jclass clz = env->FindClass("cn/yyxx/commsdk/core/utils/YYLog");
    if (clz == nullptr) {
        LOGE("YYLog clz is null");
        return;
    }
    const char *method_name = "i";
    const char *sig = "(Ljava/lang/String;Ljava/lang/Object;)V";
    jmethodID mid = env->GetStaticMethodID(clz, method_name, sig);
    jstring jtag = env->NewStringUTF(TAG);
    jstring jmsg = env->NewStringUTF(msg.c_str());
    env->CallStaticVoidMethod(clz, mid, jtag, jmsg);
}

void YYLog::E(JNIEnv *env, const std::string &msg) {
    jclass clz = env->FindClass("cn/yyxx/commsdk/core/utils/YYLog");
    if (clz == nullptr) {
        LOGE("YYLog clz is null");
        return;
    }
    const char *method_name = "e";
    const char *sig = "(Ljava/lang/String;Ljava/lang/Object;)V";
    jmethodID mid = env->GetStaticMethodID(clz, method_name, sig);
    jstring jtag = env->NewStringUTF(TAG);
    jstring jmsg = env->NewStringUTF(msg.c_str());
    env->CallStaticVoidMethod(clz, mid, jtag, jmsg);
}

void YYLog::LogHandler(JNIEnv *env, const std::string &msg) {
    jclass clz = env->FindClass("cn/yyxx/commsdk/core/utils/YYLog");
    if (clz == nullptr) {
        LOGE("YYLog clz is null");
        return;
    }
    const char *method_name = "logHandler";
    const char *sig = "(Ljava/lang/String;)V";
    jmethodID mid = env->GetStaticMethodID(clz, method_name, sig);
    jstring jmsg = env->NewStringUTF(msg.c_str());
    env->CallStaticVoidMethod(clz, mid, jmsg);
}




