diff options
author | Drew DeVault <sir@cmpwn.com> | 2015-08-08 17:01:22 -0400 |
---|---|---|
committer | Drew DeVault <sir@cmpwn.com> | 2015-08-08 17:01:27 -0400 |
commit | 0427fddb5a919ae6b3a4205e057ae36133bfbc47 (patch) | |
tree | bf4e163872f63ad955148907f4ce03b63ed5384c /sway/log.c | |
parent | Destroy outputs when appropriate (diff) | |
download | sway-0427fddb5a919ae6b3a4205e057ae36133bfbc47.tar.gz sway-0427fddb5a919ae6b3a4205e057ae36133bfbc47.tar.zst sway-0427fddb5a919ae6b3a4205e057ae36133bfbc47.zip |
Add logging and new windows into layout tree
Diffstat (limited to 'sway/log.c')
-rw-r--r-- | sway/log.c | 43 |
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 @@ | |||
1 | #include "log.h" | ||
2 | #include <stdarg.h> | ||
3 | #include <stdio.h> | ||
4 | #include <stdlib.h> | ||
5 | |||
6 | int colored = 1; | ||
7 | int v = 0; | ||
8 | |||
9 | const char *verbosity_colors[] = { | ||
10 | "", // L_SILENT | ||
11 | "\x1B[1;31m", // L_ERROR | ||
12 | "\x1B[1;34m", // L_INFO | ||
13 | "\x1B[1;30m", // L_DEBUG | ||
14 | }; | ||
15 | |||
16 | void init_log(int verbosity) { | ||
17 | v = verbosity; | ||
18 | } | ||
19 | |||
20 | void sway_abort(char *format, ...) { | ||
21 | fprintf(stderr, "ERROR: "); | ||
22 | va_list args; | ||
23 | va_start(args, format); | ||
24 | vfprintf(stderr, format, args); | ||
25 | va_end(args); | ||
26 | fprintf(stderr, "\n"); | ||
27 | exit(1); | ||
28 | } | ||
29 | |||
30 | void sway_log(int verbosity, char* format, ...) { | ||
31 | if (verbosity <= v) { | ||
32 | int c = verbosity; | ||
33 | if (c > sizeof(verbosity_colors) / sizeof(char *)) { | ||
34 | c = sizeof(verbosity_colors) / sizeof(char *) - 1; | ||
35 | } | ||
36 | fprintf(stderr, verbosity_colors[c]); | ||
37 | va_list args; | ||
38 | va_start(args, format); | ||
39 | vfprintf(stderr, format, args); | ||
40 | va_end(args); | ||
41 | fprintf(stderr, "\x1B[0m\n"); | ||
42 | } | ||
43 | } | ||