2018-09-27 03:11:10 -04:00
|
|
|
#pragma once
|
2017-09-14 21:54:56 +08:00
|
|
|
|
2020-06-01 04:15:37 -07:00
|
|
|
#include <cerrno>
|
|
|
|
#include <cstdarg>
|
|
|
|
#include <cstring>
|
2017-09-14 21:54:56 +08:00
|
|
|
|
2020-06-01 04:15:37 -07:00
|
|
|
enum {
|
2020-12-30 22:11:24 -08:00
|
|
|
L_DEBUG,
|
|
|
|
L_INFO,
|
|
|
|
L_WARN,
|
|
|
|
L_ERR
|
2020-06-01 04:15:37 -07:00
|
|
|
};
|
2018-09-27 03:11:10 -04:00
|
|
|
|
|
|
|
struct log_callback {
|
2020-12-30 22:11:24 -08:00
|
|
|
int (*d)(const char* fmt, va_list ap);
|
|
|
|
int (*i)(const char* fmt, va_list ap);
|
|
|
|
int (*w)(const char* fmt, va_list ap);
|
|
|
|
int (*e)(const char* fmt, va_list ap);
|
|
|
|
void (*ex)(int code);
|
2018-09-27 03:11:10 -04:00
|
|
|
};
|
|
|
|
|
2020-06-01 04:15:37 -07:00
|
|
|
extern log_callback log_cb;
|
2018-09-27 03:11:10 -04:00
|
|
|
|
2020-06-01 04:15:37 -07:00
|
|
|
#define LOGD(...) log_handler<L_DEBUG>(__VA_ARGS__)
|
|
|
|
#define LOGI(...) log_handler<L_INFO>(__VA_ARGS__)
|
|
|
|
#define LOGW(...) log_handler<L_WARN>(__VA_ARGS__)
|
|
|
|
#define LOGE(...) log_handler<L_ERR>(__VA_ARGS__)
|
|
|
|
#define PLOGE(fmt, args...) LOGE(fmt " failed with %d: %s\n", ##args, errno, std::strerror(errno))
|
2017-09-14 21:54:56 +08:00
|
|
|
|
2020-06-01 04:15:37 -07:00
|
|
|
int nop_log(const char *, va_list);
|
|
|
|
void nop_ex(int);
|
2017-09-14 21:54:56 +08:00
|
|
|
|
2018-09-27 03:11:10 -04:00
|
|
|
void no_logging();
|
|
|
|
void cmdline_logging();
|
2017-12-01 17:38:57 +08:00
|
|
|
|
2020-06-01 04:15:37 -07:00
|
|
|
template<int type>
|
|
|
|
void log_handler(const char *fmt, ...) __printflike(1, 2);
|