Clean up logging on C++ side

This commit is contained in:
topjohnwu 2023-05-05 01:14:56 -07:00
parent bbda0cdffe
commit c0d1bf63bc
2 changed files with 7 additions and 12 deletions

View File

@ -18,8 +18,6 @@ static int fmt_and_log_with_rs(LogLevel level, const char *fmt, va_list ap) {
return ret;
}
int (*cpp_logger)(LogLevel level, const char *fmt, va_list ap) = fmt_and_log_with_rs;
// Used to override external C library logging
extern "C" int magisk_log_print(int prio, const char *tag, const char *fmt, ...) {
LogLevel level;
@ -52,17 +50,16 @@ extern "C" int magisk_log_print(int prio, const char *tag, const char *fmt, ...)
}
va_list argv;
va_start(argv, fmt);
int ret = cpp_logger(level, fmt_buf, argv);
int ret = fmt_and_log_with_rs(level, fmt_buf, argv);
va_end(argv);
return ret;
}
#define LOG_BODY(level) { \
#define LOG_BODY(level) \
va_list argv; \
va_start(argv, fmt); \
cpp_logger(LogLevel::level, fmt, argv); \
fmt_and_log_with_rs(LogLevel::level, fmt, argv); \
va_end(argv); \
}
// LTO will optimize out the NOP function
#if MAGISK_DEBUG
@ -76,5 +73,5 @@ void LOGE(const char *fmt, ...) { LOG_BODY(Error) }
// Export raw symbol to fortify compat
extern "C" void __vloge(const char* fmt, va_list ap) {
cpp_logger(LogLevel::Error, fmt, ap);
fmt_and_log_with_rs(LogLevel::Error, fmt, ap);
}

View File

@ -5,8 +5,6 @@
#include <base-rs.hpp>
extern int (*cpp_logger)(LogLevel level, const char *fmt, va_list ap);
void LOGD(const char *fmt, ...) __printflike(1, 2);
void LOGI(const char *fmt, ...) __printflike(1, 2);
void LOGW(const char *fmt, ...) __printflike(1, 2);