aboutsummaryrefslogtreecommitdiff
path: root/include/log.h
diff options
context:
space:
mode:
authorKenny Levinsen <kl@kl.wtf>2020-07-31 00:22:18 +0200
committerKenny Levinsen <kl@kl.wtf>2020-07-31 00:22:18 +0200
commit61716a2c77dfde9addf6b41a6d72d26a8584150e (patch)
tree537cd84661955497bdb304f88896e36896df4e5f /include/log.h
parentf85434de666f10da0cbcaccdbb7d88917c5fa887 (diff)
Initial implementation of seatd and libseat
Diffstat (limited to 'include/log.h')
-rw-r--r--include/log.h51
1 files changed, 51 insertions, 0 deletions
diff --git a/include/log.h b/include/log.h
new file mode 100644
index 0000000..18a573e
--- /dev/null
+++ b/include/log.h
@@ -0,0 +1,51 @@
+#ifndef _LOG_H
+#define _LOG_H
+
+#include "compiler.h"
+#include <stdarg.h>
+
+enum libseat_log_level {
+ LIBSEAT_SILENT = 0,
+ LIBSEAT_ERROR = 1,
+ LIBSEAT_INFO = 2,
+ LIBSEAT_DEBUG = 3,
+ LIBSEAT_LOG_LEVEL_LAST,
+};
+
+void libseat_log_init(enum libseat_log_level level);
+
+void _libseat_logf(enum libseat_log_level level, const char *fmt, ...) ATTRIB_PRINTF(2, 3);
+
+#ifdef LIBSEAT_REL_SRC_DIR
+#define _LIBSEAT_FILENAME ((const char *)__FILE__ + sizeof(LIBSEAT_REL_SRC_DIR) - 1)
+#else
+#define _LIBSEAT_FILENAME __FILE__
+#endif
+
+#define log_infof(fmt, ...) \
+ _libseat_logf(LIBSEAT_INFO, "[%s:%d] %s: " fmt, _LIBSEAT_FILENAME, __LINE__, __func__, \
+ ##__VA_ARGS__)
+
+#define log_info(str) \
+ _libseat_logf(LIBSEAT_INFO, "[%s:%d] %s: %s", _LIBSEAT_FILENAME, __LINE__, __func__, str)
+
+#define log_errorf(fmt, ...) \
+ _libseat_logf(LIBSEAT_ERROR, "[%s:%d] %s: " fmt, _LIBSEAT_FILENAME, __LINE__, __func__, \
+ ##__VA_ARGS__)
+
+#define log_error(str) \
+ _libseat_logf(LIBSEAT_ERROR, "[%s:%d] %s: %s", _LIBSEAT_FILENAME, __LINE__, __func__, str)
+
+#ifdef DEBUG
+#define log_debugf(fmt, ...) \
+ _libseat_logf(LIBSEAT_DEBUG, "[%s:%d] %s: " fmt, _LIBSEAT_FILENAME, __LINE__, __func__, \
+ ##__VA_ARGS__)
+
+#define log_debug(str) \
+ _libseat_logf(LIBSEAT_DEBUG, "[%s:%d] %s: %s", _LIBSEAT_FILENAME, __LINE__, __func__, str)
+#else
+#define log_debugf(fmt, ...)
+#define log_debug(str)
+#endif
+
+#endif