2017-09-14 15:54:56 +02:00
|
|
|
/* logging.h - Error handling and logging
|
|
|
|
*/
|
|
|
|
|
2018-09-27 09:11:10 +02:00
|
|
|
#pragma once
|
2017-09-14 15:54:56 +02:00
|
|
|
|
|
|
|
#include <errno.h>
|
2018-09-27 09:11:10 +02:00
|
|
|
#include <stdarg.h>
|
|
|
|
#include <string.h>
|
2017-09-14 15:54:56 +02:00
|
|
|
|
2017-11-05 22:41:03 +01:00
|
|
|
#define str(a) #a
|
|
|
|
#define xstr(a) str(a)
|
|
|
|
|
2018-09-27 09:11:10 +02:00
|
|
|
typedef enum {
|
|
|
|
L_DEBUG,
|
|
|
|
L_INFO,
|
|
|
|
L_WARN,
|
|
|
|
L_ERR
|
|
|
|
} log_type;
|
|
|
|
|
|
|
|
struct log_callback {
|
|
|
|
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);
|
|
|
|
};
|
|
|
|
|
|
|
|
extern struct log_callback log_cb;
|
|
|
|
|
|
|
|
#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__)
|
2017-10-13 16:25:16 +02:00
|
|
|
#define PLOGE(fmt, args...) LOGE(fmt " failed with %d: %s", ##args, errno, strerror(errno))
|
2017-09-14 15:54:56 +02:00
|
|
|
|
2018-09-27 09:11:10 +02:00
|
|
|
int nop_log(const char *fmt, va_list ap);
|
|
|
|
void nop_ex(int i);
|
2017-09-14 15:54:56 +02:00
|
|
|
|
2018-09-27 09:11:10 +02:00
|
|
|
void no_logging();
|
|
|
|
void android_logging();
|
|
|
|
void cmdline_logging();
|
2017-12-01 10:38:57 +01:00
|
|
|
|
2018-09-27 09:11:10 +02:00
|
|
|
int log_handler(log_type t, const char *fmt, ...);
|
2017-09-14 15:54:56 +02:00
|
|
|
|