summaryrefslogtreecommitdiff
path: root/sources/log.c
diff options
context:
space:
mode:
Diffstat (limited to 'sources/log.c')
-rw-r--r--sources/log.c40
1 files changed, 40 insertions, 0 deletions
diff --git a/sources/log.c b/sources/log.c
new file mode 100644
index 0000000..ba0aa86
--- /dev/null
+++ b/sources/log.c
@@ -0,0 +1,40 @@
+typedef enum log_kind
+{
+ LK_DEBUG,
+ LK_INFO,
+ LK_WARN,
+ LK_ERROR,
+ LK_FATAL,
+
+ LK_ENUM_LEN
+
+} log_kind;
+
+static char* log_kind_names[LK_ENUM_LEN] =
+{
+ "DEBUG",
+ "INFO",
+ "WARN",
+ "ERROR",
+ "FATAL",
+};
+
+#define DBG LK_DEBUG, __FILE__, __LINE__
+#define INFO LK_INFO, __FILE__, __LINE__
+#define WARN LK_WARN, __FILE__, __LINE__
+#define ERR LK_ERROR, __FILE__, __LINE__
+#define FATAL LK_FATAL, __FILE__, __LINE__
+
+void report(log_kind kind, const char* file, int line, const char* fmt, ...)
+{
+ va_list ap;
+
+ /* TODO: log levels */
+
+ printf("[%s] %s:%d - ", log_kind_names[kind], file, line);
+ va_start(ap, fmt);
+ vprintf(fmt, ap);
+ va_end(ap);
+
+ if(kind == LK_FATAL) abort();
+}