aboutsummaryrefslogtreecommitdiff
path: root/client/libacron/apps/acronc/log.c
diff options
context:
space:
mode:
Diffstat (limited to 'client/libacron/apps/acronc/log.c')
-rw-r--r--client/libacron/apps/acronc/log.c61
1 files changed, 61 insertions, 0 deletions
diff --git a/client/libacron/apps/acronc/log.c b/client/libacron/apps/acronc/log.c
new file mode 100644
index 0000000..08f48b6
--- /dev/null
+++ b/client/libacron/apps/acronc/log.c
@@ -0,0 +1,61 @@
+/*
+ * Created by yuuta on 1/1/22.
+ */
+
+#define _GNU_SOURCE
+
+#include "log.h"
+#include "config.h"
+
+#include <stdio.h>
+#include <stdarg.h>
+#include <assert.h>
+
+#ifdef __linux__
+#include <sys/types.h>
+#include <unistd.h>
+#include <sys/syscall.h>
+#endif
+
+void g_log(enum log_level level,
+ const char *file,
+ int line,
+ const char *format,
+ ...) {
+ FILE *stream = stderr;
+ switch (level) {
+ case log_fetal:
+ fprintf(stream, "F");
+ break;
+ case log_error:
+ fprintf(stream, "E");
+ break;
+ case log_warn:
+ fprintf(stream, "W");
+ break;
+ case log_info:
+ fprintf(stream, "I");
+ break;
+ case log_debug:
+#ifdef DEBUG
+ fprintf(stream, "D");
+ break;
+#else
+ return;
+#endif
+ default:
+ fprintf(stderr, "Unknown log level: %d.\n", level);
+ assert(0);
+ }
+ int tid = -1;
+#ifdef __linux__
+ tid = (int) syscall(__NR_gettid);
+#endif
+ fprintf(stream, "[%d %s:%d]: ",
+ tid, file, line);
+ va_list list;
+ va_start(list, format);
+ vfprintf(stream, format, list);
+ va_end(list);
+ fprintf(stream, "\n");
+}