logger.cpp 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. //
  2. // Created by #Suyghur, on 2021/06/21.
  3. //
  4. #include "include/logger.h"
  5. bool Logger::is_debug = true;
  6. void Logger::D(JNIEnv *env, const std::string &msg) {
  7. if (is_debug) {
  8. jclass clz = env->FindClass("cn/yyxx/columbus/base/utils/Logger");
  9. if (clz == nullptr) {
  10. LOGE("Logger clz is null");
  11. return;
  12. }
  13. const char *method_name = "d";
  14. const char *sig = "(Ljava/lang/String;Ljava/lang/Object;)V";
  15. jmethodID mid = env->GetStaticMethodID(clz, method_name, sig);
  16. jstring jtag = env->NewStringUTF(TAG);
  17. jstring jmsg = env->NewStringUTF(msg.c_str());
  18. env->CallStaticVoidMethod(clz, mid, jtag, jmsg);
  19. }
  20. }
  21. void Logger::I(JNIEnv *env, const std::string &msg) {
  22. jclass clz = env->FindClass("cn/yyxx/columbus/base/utils/Logger");
  23. if (clz == nullptr) {
  24. LOGE("Logger clz is null");
  25. return;
  26. }
  27. const char *method_name = "i";
  28. const char *sig = "(Ljava/lang/String;Ljava/lang/Object;)V";
  29. jmethodID mid = env->GetStaticMethodID(clz, method_name, sig);
  30. jstring jtag = env->NewStringUTF(TAG);
  31. jstring jmsg = env->NewStringUTF(msg.c_str());
  32. env->CallStaticVoidMethod(clz, mid, jtag, jmsg);
  33. }
  34. void Logger::E(JNIEnv *env, const std::string &msg) {
  35. jclass clz = env->FindClass("cn/yyxx/columbus/base/utils/Logger");
  36. if (clz == nullptr) {
  37. LOGE("Logger clz is null");
  38. return;
  39. }
  40. const char *method_name = "e";
  41. const char *sig = "(Ljava/lang/String;Ljava/lang/Object;)V";
  42. jmethodID mid = env->GetStaticMethodID(clz, method_name, sig);
  43. jstring jtag = env->NewStringUTF(TAG);
  44. jstring jmsg = env->NewStringUTF(msg.c_str());
  45. env->CallStaticVoidMethod(clz, mid, jtag, jmsg);
  46. }
  47. void Logger::LogHandler(JNIEnv *env, const std::string &msg) {
  48. jclass clz = env->FindClass("cn/yyxx/columbus/base/utils/Logger");
  49. if (clz == nullptr) {
  50. LOGE("Logger clz is null");
  51. return;
  52. }
  53. const char *method_name = "logHandler";
  54. const char *sig = "(Ljava/lang/String;)V";
  55. jmethodID mid = env->GetStaticMethodID(clz, method_name, sig);
  56. jstring jmsg = env->NewStringUTF(msg.c_str());
  57. env->CallStaticVoidMethod(clz, mid, jmsg);
  58. }