Magisk/native/jni/utils/logging.cpp

62 lines
974 B
C++
Raw Normal View History

2018-09-27 09:11:10 +02:00
#include <stdio.h>
#include <stdlib.h>
2020-03-09 09:50:30 +01:00
#include <logging.hpp>
2018-09-27 09:11:10 +02:00
int nop_log(const char *fmt, va_list ap) {
return 0;
}
void nop_ex(int i) {}
struct log_callback log_cb = {
.d = nop_log,
.i = nop_log,
.w = nop_log,
.e = nop_log,
.ex = nop_ex
};
void no_logging() {
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;
}
static int vprinte(const char *fmt, va_list ap) {
return vfprintf(stderr, fmt, ap);
}
void cmdline_logging() {
log_cb.d = vprinte;
log_cb.i = vprintf;
log_cb.w = vprinte;
log_cb.e = vprinte;
log_cb.ex = exit;
}
int log_handler(log_type t, const char *fmt, ...) {
va_list argv;
int ret = 0;
va_start(argv, fmt);
switch (t) {
2020-05-10 09:48:41 +02:00
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;
2018-09-27 09:11:10 +02:00
}
va_end(argv);
return ret;
}