2020-06-01 11:15:37 +00:00
|
|
|
#include <cstdio>
|
|
|
|
#include <cstdlib>
|
2018-09-27 07:11:10 +00:00
|
|
|
|
2021-09-08 02:35:28 +00:00
|
|
|
#include <flags.h>
|
2018-09-27 07:11:10 +00:00
|
|
|
|
2021-08-12 10:26:54 +00:00
|
|
|
#include "logging.hpp"
|
|
|
|
|
2020-06-01 11:15:37 +00:00
|
|
|
using namespace std;
|
|
|
|
|
|
|
|
int nop_log(const char *, va_list) { return 0; }
|
2018-09-27 07:11:10 +00:00
|
|
|
|
2020-06-01 11:15:37 +00:00
|
|
|
void nop_ex(int) {}
|
2018-09-27 07:11:10 +00:00
|
|
|
|
2020-06-01 11:15:37 +00:00
|
|
|
log_callback log_cb = {
|
2020-12-31 06:11:24 +00:00
|
|
|
.d = nop_log,
|
|
|
|
.i = nop_log,
|
|
|
|
.w = nop_log,
|
|
|
|
.e = nop_log,
|
|
|
|
.ex = nop_ex
|
2018-09-27 07:11:10 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
void no_logging() {
|
2020-12-31 06:11:24 +00:00
|
|
|
log_cb.d = nop_log;
|
|
|
|
log_cb.i = nop_log;
|
|
|
|
log_cb.w = nop_log;
|
|
|
|
log_cb.e = nop_log;
|
|
|
|
log_cb.ex = nop_ex;
|
2018-09-27 07:11:10 +00:00
|
|
|
}
|
|
|
|
|
2020-06-01 11:15:37 +00:00
|
|
|
static int vprintfe(const char *fmt, va_list ap) {
|
2020-12-31 06:11:24 +00:00
|
|
|
return vfprintf(stderr, fmt, ap);
|
2018-09-27 07:11:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void cmdline_logging() {
|
2020-12-31 06:11:24 +00:00
|
|
|
log_cb.d = vprintfe;
|
|
|
|
log_cb.i = vprintf;
|
|
|
|
log_cb.w = vprintfe;
|
|
|
|
log_cb.e = vprintfe;
|
|
|
|
log_cb.ex = exit;
|
2018-09-27 07:11:10 +00:00
|
|
|
}
|
|
|
|
|
2021-08-12 10:26:54 +00:00
|
|
|
#define LOG_BODY(prio) { \
|
|
|
|
va_list argv; \
|
|
|
|
va_start(argv, fmt); \
|
|
|
|
log_cb.prio(fmt, argv); \
|
|
|
|
va_end(argv); \
|
2018-09-27 07:11:10 +00:00
|
|
|
}
|
2020-06-01 11:15:37 +00:00
|
|
|
|
2021-08-12 10:26:54 +00:00
|
|
|
// LTO will optimize out the NOP function
|
2021-09-08 02:35:28 +00:00
|
|
|
#if MAGISK_DEBUG
|
2021-08-12 10:26:54 +00:00
|
|
|
void LOGD(const char *fmt, ...) { LOG_BODY(d) }
|
2020-06-01 11:15:37 +00:00
|
|
|
#else
|
2021-08-12 10:26:54 +00:00
|
|
|
void LOGD(const char *fmt, ...) {}
|
2020-06-01 11:15:37 +00:00
|
|
|
#endif
|
2021-08-12 10:26:54 +00:00
|
|
|
void LOGI(const char *fmt, ...) { LOG_BODY(i) }
|
|
|
|
void LOGW(const char *fmt, ...) { LOG_BODY(w) }
|
2021-07-22 15:35:14 +00:00
|
|
|
void LOGE(const char *fmt, ...) { LOG_BODY(e); log_cb.ex(EXIT_FAILURE); }
|