diff --git a/native/jni/core/daemon.cpp b/native/jni/core/daemon.cpp index 828c4bf9f..7818bf76a 100644 --- a/native/jni/core/daemon.cpp +++ b/native/jni/core/daemon.cpp @@ -1,13 +1,11 @@ -#include -#include #include -#include #include #include #include #include #include #include +#include #include #include @@ -112,6 +110,19 @@ static void *request_handler(void *args) { return nullptr; } +static void android_logging() { + static constexpr char TAG[] = "Magisk"; +#ifdef MAGISK_DEBUG + log_cb.d = [](auto fmt, auto ap){ return __android_log_vprint(ANDROID_LOG_DEBUG, TAG, fmt, ap); }; +#else + log_cb.d = nop_log; +#endif + log_cb.i = [](auto fmt, auto ap){ return __android_log_vprint(ANDROID_LOG_INFO, TAG, fmt, ap); }; + log_cb.w = [](auto fmt, auto ap){ return __android_log_vprint(ANDROID_LOG_WARN, TAG, fmt, ap); }; + log_cb.e = [](auto fmt, auto ap){ return __android_log_vprint(ANDROID_LOG_ERROR, TAG, fmt, ap); }; + log_cb.ex = nop_ex; +} + static void daemon_entry(int ppid) { android_logging(); diff --git a/native/jni/utils/include/logging.hpp b/native/jni/utils/include/logging.hpp index d4676f044..211c55db8 100644 --- a/native/jni/utils/include/logging.hpp +++ b/native/jni/utils/include/logging.hpp @@ -33,7 +33,6 @@ int nop_log(const char *fmt, va_list ap); void nop_ex(int i); void no_logging(); -void android_logging(); void cmdline_logging(); int log_handler(log_type t, const char *fmt, ...); diff --git a/native/jni/utils/logging.cpp b/native/jni/utils/logging.cpp index 57fdb77cf..be49ad1ce 100644 --- a/native/jni/utils/logging.cpp +++ b/native/jni/utils/logging.cpp @@ -1,9 +1,7 @@ #include #include -#include #include -#include int nop_log(const char *fmt, va_list ap) { return 0; @@ -27,36 +25,6 @@ void no_logging() { log_cb.ex = nop_ex; } -#define LOG_TAG "Magisk" - -[[maybe_unused]] static int log_d(const char *fmt, va_list ap) { - return __android_log_vprint(ANDROID_LOG_DEBUG, LOG_TAG, fmt, ap); -} - -static int log_i(const char *fmt, va_list ap) { - return __android_log_vprint(ANDROID_LOG_INFO, LOG_TAG, fmt, ap); -} - -static int log_w(const char *fmt, va_list ap) { - return __android_log_vprint(ANDROID_LOG_WARN, LOG_TAG, fmt, ap); -} - -static int log_e(const char *fmt, va_list ap) { - return __android_log_vprint(ANDROID_LOG_ERROR, LOG_TAG, fmt, ap); -} - -void android_logging() { -#ifdef MAGISK_DEBUG - log_cb.d = log_d; -#else - log_cb.d = nop_log; -#endif - log_cb.i = log_i; - log_cb.w = log_w; - log_cb.e = log_e; - log_cb.ex = nop_ex; -} - static int vprinte(const char *fmt, va_list ap) { return vfprintf(stderr, fmt, ap); } @@ -74,19 +42,19 @@ int log_handler(log_type t, const char *fmt, ...) { int ret = 0; va_start(argv, fmt); switch (t) { - case L_DEBUG: - ret = log_cb.d(fmt, argv); - break; - case L_INFO: - ret = log_cb.i(fmt, argv); - break; - case L_WARN: - ret = log_cb.w(fmt, argv); - break; - case L_ERR: - ret = log_cb.e(fmt, argv); - log_cb.ex(1); - break; + case L_DEBUG: + ret = log_cb.d(fmt, argv); + break; + case L_INFO: + ret = log_cb.i(fmt, argv); + break; + case L_WARN: + ret = log_cb.w(fmt, argv); + break; + case L_ERR: + ret = log_cb.e(fmt, argv); + log_cb.ex(1); + break; } va_end(argv); return ret;