23 #define LOG_VERSION "0.1.0"
24 #define __FILENAME__ strrchr("/" __FILE__, '/') + 1
25 #define MAX_LOG_LEVELS 5
32 { "TRACE", "DEBUG", "INFO", "WARN", "ERROR" }
33 #define LEVEL_COLORS \
34 { "\x1b[94m", "\x1b[36m", "\x1b[32m", "\x1b[33m", "\x1b[31m" }
36 #if defined __has_attribute
37 #if __has_attribute(format)
45 #define PRINTF_FORMAT(a, b) __attribute__((format(printf, (a), (b))))
47 #define PRINTF_FORMAT(a, b)
50 #define PRINTF_FORMAT(a, b)
53 static inline int snprintf_error(
size_t size,
int res) {
54 return res < 0 || (
unsigned int)res >= size;
57 #define log_trace(...) \
58 log_levels(LOGC_TRACE, __FILENAME__, __LINE__, __VA_ARGS__)
59 #define log_debug(...) \
60 log_levels(LOGC_DEBUG, __FILENAME__, __LINE__, __VA_ARGS__)
61 #define log_info(...) log_levels(LOGC_INFO, __FILENAME__, __LINE__, __VA_ARGS__)
62 #define log_warn(...) log_levels(LOGC_WARN, __FILENAME__, __LINE__, __VA_ARGS__)
68 #define log_error(...) \
69 log_levels(LOGC_ERROR, __FILENAME__, __LINE__, __VA_ARGS__)
75 #define log_errno(...) \
76 log_errno_error(LOGC_ERROR, __FILENAME__, __LINE__, __VA_ARGS__)
78 #define log_err_ex(...) \
79 log_error_exit(LOGC_ERROR, __FILENAME__, __LINE__, __VA_ARGS__)
80 #define log_err_exp(...) \
81 log_error_exit_proc(LOGC_ERROR, __FILENAME__, __LINE__, __VA_ARGS__)
94 const
char *format, ...);
97 const
char *format, ...);
100 const
char *format, ...);
103 const
char *format, ...);
128 size_t printf_hex(
char *buf,
size_t buf_size, const uint8_t *data,
size_t len,
log_lock_fn lock
Definition: log.c:56
uint8_t level
Definition: log.c:57
@ LOGC_WARN
Definition: log.h:29
@ LOGC_DEBUG
Definition: log.h:29
@ LOGC_ERROR
Definition: log.h:29
@ LOGC_TRACE
Definition: log.h:29
@ LOGC_INFO
Definition: log.h:29
void(* log_lock_fn)(bool lock)
Definition: log.h:27
void log_set_level(uint8_t level)
Definition: log.c:139
void log_set_color(bool enable)
Definition: log.c:145
size_t printf_hex(char *buf, size_t buf_size, const uint8_t *data, size_t len, bool uppercase)
Prints the data in data to buf as hex.
Definition: log.c:324
#define PRINTF_FORMAT(a, b)
Definition: log.h:50
void log_set_meta(bool enable)
Definition: log.c:143
void log_close_file(void)
Definition: log.c:167
void log_errno_error(uint8_t level, const char *file, uint32_t line, const char *format,...)
Definition: log.c:268
void log_error_exit(uint8_t level, const char *file, uint32_t line, const char *format,...)
Definition: log.c:282
void log_set_udata(void *udata)
void log_set_lock(log_lock_fn fn)
Definition: log.c:137
void log_set_quiet(bool enable)
Definition: log.c:141
int log_open_file(char *path)
Definition: log.c:147
void log_error_exit_proc(uint8_t level, const char *file, uint32_t line, const char *format,...)
Definition: log.c:310
void log_levels(uint8_t level, const char *file, uint32_t line, const char *format,...)
Definition: log.c:259