aboutsummaryrefslogtreecommitdiff
path: root/sway/log.c
diff options
context:
space:
mode:
authorDrew DeVault <sir@cmpwn.com>2015-08-08 17:01:22 -0400
committerDrew DeVault <sir@cmpwn.com>2015-08-08 17:01:27 -0400
commit0427fddb5a919ae6b3a4205e057ae36133bfbc47 (patch)
treebf4e163872f63ad955148907f4ce03b63ed5384c /sway/log.c
parent2786fa2215bf6d66a7e4feea4e7e12b0dc8d4ba4 (diff)
Add logging and new windows into layout tree
Diffstat (limited to 'sway/log.c')
-rw-r--r--sway/log.c43
1 files changed, 43 insertions, 0 deletions
diff --git a/sway/log.c b/sway/log.c
new file mode 100644
index 00000000..6ac7026f
--- /dev/null
+++ b/sway/log.c
@@ -0,0 +1,43 @@
+#include "log.h"
+#include <stdarg.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+int colored = 1;
+int v = 0;
+
+const char *verbosity_colors[] = {
+ "", // L_SILENT
+ "\x1B[1;31m", // L_ERROR
+ "\x1B[1;34m", // L_INFO
+ "\x1B[1;30m", // L_DEBUG
+};
+
+void init_log(int verbosity) {
+ v = verbosity;
+}
+
+void sway_abort(char *format, ...) {
+ fprintf(stderr, "ERROR: ");
+ va_list args;
+ va_start(args, format);
+ vfprintf(stderr, format, args);
+ va_end(args);
+ fprintf(stderr, "\n");
+ exit(1);
+}
+
+void sway_log(int verbosity, char* format, ...) {
+ if (verbosity <= v) {
+ int c = verbosity;
+ if (c > sizeof(verbosity_colors) / sizeof(char *)) {
+ c = sizeof(verbosity_colors) / sizeof(char *) - 1;
+ }
+ fprintf(stderr, verbosity_colors[c]);
+ va_list args;
+ va_start(args, format);
+ vfprintf(stderr, format, args);
+ va_end(args);
+ fprintf(stderr, "\x1B[0m\n");
+ }
+}