summaryrefslogtreecommitdiff
path: root/experimental/tectonics/logging.c
diff options
context:
space:
mode:
Diffstat (limited to 'experimental/tectonics/logging.c')
-rw-r--r--experimental/tectonics/logging.c42
1 files changed, 42 insertions, 0 deletions
diff --git a/experimental/tectonics/logging.c b/experimental/tectonics/logging.c
new file mode 100644
index 0000000..ec416d6
--- /dev/null
+++ b/experimental/tectonics/logging.c
@@ -0,0 +1,42 @@
+#include <stdio.h>
+#include <stdarg.h>
+
+#include "logging.h"
+
+int global_log_level;
+
+const char *level_string(int level)
+{
+ switch(level) {
+ case FATAL:
+ return "FATAL";
+ case ERROR:
+ return "ERROR";
+ case WARN:
+ return "WARN";
+ case INFO:
+ return "INFO";
+ case DEBUG:
+ return "DEBUG";
+ case TRACE:
+ return "TRACE";
+
+ default:
+ if (level > TRACE)
+ return "TRACE";
+ return "[BAD LOG LEVEL]";
+ }
+}
+
+
+void log_msg(int level, const char *format_string, ...)
+{
+ if (global_log_level >= level) {
+ va_list args;
+ va_start(args, format_string);
+ fprintf(stderr, "[%s] ", level_string(level));
+ vfprintf(stderr, format_string, args);
+ fprintf(stderr, "\n");
+ va_end(args);
+ }
+}