summaryrefslogtreecommitdiff
path: root/kernel_call/log.c
diff options
context:
space:
mode:
Diffstat (limited to 'kernel_call/log.c')
-rwxr-xr-xkernel_call/log.c37
1 files changed, 37 insertions, 0 deletions
diff --git a/kernel_call/log.c b/kernel_call/log.c
new file mode 100755
index 0000000..0ff5f01
--- /dev/null
+++ b/kernel_call/log.c
@@ -0,0 +1,37 @@
+/*
+ * log.c
+ * Brandon Azad
+ */
+#include "log.h"
+
+#include <assert.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+void
+log_internal(char type, const char *format, ...) {
+ if (log_implementation != NULL) {
+ va_list ap;
+ va_start(ap, format);
+ log_implementation(type, format, ap);
+ va_end(ap);
+ }
+}
+
+// The default logging implementation prints to stderr with a nice hacker prefix.
+static void
+log_stderr(char type, const char *format, va_list ap) {
+ char *message = NULL;
+ vasprintf(&message, format, ap);
+ assert(message != NULL);
+ switch (type) {
+ case 'D': type = 'D'; break;
+ case 'I': type = '+'; break;
+ case 'W': type = '!'; break;
+ case 'E': type = '-'; break;
+ }
+ fprintf(stderr, "[%c] %s\n", type, message);
+ free(message);
+}
+
+void (*log_implementation)(char type, const char *format, va_list ap) = log_stderr;