| 888 | } |
| 889 | |
| 890 | void InnerLog(int level, std::string traceId, const char *fmt, ...) { |
| 891 | std::string _tag = "jni|" + traceId; |
| 892 | |
| 893 | char msg[2048] = {0}; |
| 894 | va_list args; |
| 895 | va_start(args, fmt); |
| 896 | vsnprintf(msg, 2048, fmt, args); |
| 897 | va_end(args); |
| 898 | |
| 899 | jmethodID method = gF2LogInfoMethod; |
| 900 | if(level == F2_LOG_WARN) { |
| 901 | method = gF2LogWarnMethod; |
| 902 | } else if(level == F2_LOG_ERROR) { |
| 903 | method = gF2LogErrorMethod; |
| 904 | } |
| 905 | |
| 906 | if(gF2LogClass == nullptr || gF2LogClass->isNull() || method == nullptr) { |
| 907 | native_clog(level, _tag.data(), msg); |
| 908 | return; |
| 909 | } |
| 910 | |
| 911 | JNIEnv *env = GetJniEnvSafe(); |
| 912 | if(env == nullptr) { |
| 913 | return; |
| 914 | } |
| 915 | ScopedJavaLocalRef<jstring> tagStr = StringToJavaString(env, _tag); |
| 916 | ScopedJavaLocalRef<jstring> msgStr = StringToJavaString(env, msg); |
| 917 | env->CallVoidMethod(gF2LogClass->obj(), method, tagStr.obj(), msgStr.obj()); |
| 918 | if(HasException(env)) { |
| 919 | jni::ClearException(env); |
| 920 | } |
| 921 | } |
| 922 | |
| 923 | static bool OnJniLoad(JNIEnv *env) { |
| 924 | if(!InitF2Log(env)) { |
nothing calls this directly
no test coverage detected