diff options
author | Yaroslav de la Peña Smirnov <yps@yaroslavps.com> | 2021-11-07 02:02:45 +0300 |
---|---|---|
committer | Yaroslav de la Peña Smirnov <yps@yaroslavps.com> | 2021-11-07 02:02:45 +0300 |
commit | e3a41da5a0a3d70ac53591f2b66144f2be2b3871 (patch) | |
tree | 789cc69b05f2447c11f04dbb6ae972ffa0acd1c9 /include/log.h | |
download | revela-e3a41da5a0a3d70ac53591f2b66144f2be2b3871.tar.gz revela-e3a41da5a0a3d70ac53591f2b66144f2be2b3871.zip |
Initial commit.
Almost functional but still missing features and lacking testing.
Diffstat (limited to 'include/log.h')
-rw-r--r-- | include/log.h | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/include/log.h b/include/log.h new file mode 100644 index 0000000..2be35ee --- /dev/null +++ b/include/log.h @@ -0,0 +1,58 @@ +#ifndef REVELA_LOG_H +#define REVELA_LOG_H + +#include <errno.h> +#include <string.h> + +enum log_level { + LOG_SILENT, + LOG_FATAL, + LOG_ERROR, + LOG_INFO, + LOG_DETAIL, + LOG_DEBUG, +}; + +#ifdef DEBUG +static const char *log_level_names[] = { + "", + "FATAL", + "ERROR", + "INFO", + "DETAIL", + "DEBUG", +}; +#endif + +void log_set_verbosity(enum log_level); + +void log_printf(enum log_level, const char *restrict fmt, ...); + +#ifdef DEBUG +#define log_print(v, fmt, ...) \ + log_printf(v, "[%s] %s:%d " fmt, log_level_names[v], \ + __FILE__, __LINE__, ##__VA_ARGS__) +#else +#define log_print(v, fmt, ...) \ + log_printf(v, fmt, ##__VA_ARGS__) +#endif + +#ifdef DEBUG +#define log_printl(v, fmt, ...) \ + log_printf(v, "[%s] %s:%d " fmt "\n", log_level_names[v], \ + __FILE__, __LINE__, ##__VA_ARGS__) +#else +#define log_printl(v, fmt, ...) \ + log_printf(v, fmt "\n", ##__VA_ARGS__) +#endif + +#ifdef DEBUG +#define log_printl_errno(v, fmt, ...) \ + log_printf(v, "[%s] %s:%d " fmt ": %s\n", log_level_names[v], \ + __FILE__, __LINE__, ##__VA_ARGS__, strerror(errno)) +#else +#define log_printl_errno(v, fmt, ...) \ + log_printf(v, fmt ": %s\n", ##__VA_ARGS__, strerror(errno)) +#endif + +#endif |