summaryrefslogtreecommitdiff
path: root/lib/log.h
diff options
context:
space:
mode:
Diffstat (limited to 'lib/log.h')
-rw-r--r--lib/log.h23
1 files changed, 23 insertions, 0 deletions
diff --git a/lib/log.h b/lib/log.h
new file mode 100644
index 0000000..e1cdcb8
--- /dev/null
+++ b/lib/log.h
@@ -0,0 +1,23 @@
+#include <stdio.h>
+
+enum { LOGL_TRACE, LOGL_DEBUG, LOGL_INFO, LOGL_WARN, LOGL_ERROR, LOGL_FATAL };
+
+/*
+ * log_info("Hello %s!", "World");
+ * log_warn("warning");
+ */
+#define log_trace(...) dp_log_write(LOGL_TRACE, __FILE__, __LINE__, __VA_ARGS__)
+#define log_debug(...) dp_log_write(LOGL_DEBUG, __FILE__, __LINE__, __VA_ARGS__)
+#define log_info(...) dp_log_write(LOGL_INFO, __FILE__, __LINE__, __VA_ARGS__)
+#define log_warn(...) dp_log_write(LOGL_WARN, __FILE__, __LINE__, __VA_ARGS__)
+#define log_error(...) dp_log_write(LOGL_ERROR, __FILE__, __LINE__, __VA_ARGS__)
+#define log_fatal(...) dp_log_write(LOGL_FATAL, __FILE__, __LINE__, __VA_ARGS__)
+
+void dp_log_set_output(void (*)(int level, const char *source, int line, const char *msg));
+
+/*
+ * Sets the minimum log level. Level is inclusive.
+ */
+void dp_log_set_level(int level);
+
+void dp_log_write(int level, const char *source, int line, const char *fmt, ...);