2023-05-25 21:04:55 +02:00
|
|
|
#ifndef LANDER_LOG
|
|
|
|
#define LANDER_LOG
|
|
|
|
|
|
|
|
#include <stdarg.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
|
2023-05-31 13:09:16 +02:00
|
|
|
extern const char *log_level_names[];
|
|
|
|
|
2023-05-25 21:04:55 +02:00
|
|
|
typedef enum log_level {
|
|
|
|
log_level_debug = 0,
|
|
|
|
log_level_info = 1,
|
|
|
|
log_level_warning = 2,
|
|
|
|
log_level_error = 3,
|
|
|
|
log_level_critical = 4,
|
|
|
|
} log_level;
|
|
|
|
|
2023-05-31 13:09:16 +02:00
|
|
|
extern log_level _log_level;
|
2023-05-25 21:04:55 +02:00
|
|
|
|
|
|
|
void _lander_log(log_level level, FILE *f, const char *fmt, ...);
|
|
|
|
|
2023-05-31 13:09:16 +02:00
|
|
|
#define log_level(level) _log_level = level
|
|
|
|
|
2023-05-25 21:04:55 +02:00
|
|
|
#define flog(level, f, ...) _lander_log(level, f, __VA_ARGS__)
|
|
|
|
#define log(level, ...) _lander_log(level, NULL, __VA_ARGS__)
|
|
|
|
#define debug(...) _lander_log(log_level_debug, NULL, __VA_ARGS__)
|
|
|
|
#define fdebug(f, ...) _lander_log(log_level_debug, f, __VA_ARGS__)
|
|
|
|
#define info(...) _lander_log(log_level_info, NULL, __VA_ARGS__)
|
|
|
|
#define finfo(f, ...) _lander_log(log_level_info, f, __VA_ARGS__)
|
|
|
|
#define warning(...) _lander_log(log_level_warning, NULL, __VA_ARGS__)
|
|
|
|
#define fwarning(f, ...) _lander_log(log_level_warning, f, __VA_ARGS__)
|
|
|
|
#define error(...) _lander_log(log_level_error, NULL, __VA_ARGS__)
|
|
|
|
#define ferror(f, ...) _lander_log(log_level_error, f, __VA_ARGS__)
|
|
|
|
#define critical(status, ...) \
|
|
|
|
_lander_log(log_level_critical, NULL, __VA_ARGS__); \
|
|
|
|
exit(status)
|
|
|
|
#define fcritical(status, f, ...) \
|
|
|
|
_lander_log(log_level_critical, f, __VA_ARGS__); \
|
|
|
|
exit(status)
|
|
|
|
|
|
|
|
#endif
|