diff options
author | Drew DeVault <sir@cmpwn.com> | 2015-11-11 08:32:32 -0500 |
---|---|---|
committer | Drew DeVault <sir@cmpwn.com> | 2015-11-11 08:32:32 -0500 |
commit | d729032ba2e8da8b4efa4b3112231662c6912f98 (patch) | |
tree | 18da4d079539dcc53bf15b5a967b448ac1d5082c /sway | |
parent | Add some documentation comments (diff) | |
download | sway-d729032ba2e8da8b4efa4b3112231662c6912f98.tar.gz sway-d729032ba2e8da8b4efa4b3112231662c6912f98.tar.zst sway-d729032ba2e8da8b4efa4b3112231662c6912f98.zip |
Add file and line number to log in Debug build
Diffstat (limited to 'sway')
-rw-r--r-- | sway/log.c | 13 |
1 files changed, 12 insertions, 1 deletions
@@ -3,11 +3,13 @@ | |||
3 | #include <stdarg.h> | 3 | #include <stdarg.h> |
4 | #include <stdio.h> | 4 | #include <stdio.h> |
5 | #include <stdlib.h> | 5 | #include <stdlib.h> |
6 | #include <libgen.h> | ||
6 | #include <fcntl.h> | 7 | #include <fcntl.h> |
7 | #include <unistd.h> | 8 | #include <unistd.h> |
8 | #include <signal.h> | 9 | #include <signal.h> |
9 | #include <errno.h> | 10 | #include <errno.h> |
10 | #include <string.h> | 11 | #include <string.h> |
12 | #include <stringop.h> | ||
11 | #include <execinfo.h> | 13 | #include <execinfo.h> |
12 | 14 | ||
13 | int colored = 1; | 15 | int colored = 1; |
@@ -59,7 +61,11 @@ void sway_abort(const char *format, ...) { | |||
59 | sway_terminate(); | 61 | sway_terminate(); |
60 | } | 62 | } |
61 | 63 | ||
62 | void sway_log(log_importance_t verbosity, const char* format, ...) { | 64 | #ifndef NDEBUG |
65 | void _sway_log(const char *filename, int line, log_importance_t verbosity, const char* format, ...) { | ||
66 | #else | ||
67 | void _sway_log(log_importance_t verbosity, const char* format, ...) { | ||
68 | #endif | ||
63 | if (verbosity <= v) { | 69 | if (verbosity <= v) { |
64 | unsigned int c = verbosity; | 70 | unsigned int c = verbosity; |
65 | if (c > sizeof(verbosity_colors) / sizeof(char *)) { | 71 | if (c > sizeof(verbosity_colors) / sizeof(char *)) { |
@@ -72,6 +78,11 @@ void sway_log(log_importance_t verbosity, const char* format, ...) { | |||
72 | 78 | ||
73 | va_list args; | 79 | va_list args; |
74 | va_start(args, format); | 80 | va_start(args, format); |
81 | #ifndef NDEBUG | ||
82 | char *file = strdup(filename); | ||
83 | fprintf(stderr, "[%s:%d] ", basename(file), line); | ||
84 | free(file); | ||
85 | #endif | ||
75 | vfprintf(stderr, format, args); | 86 | vfprintf(stderr, format, args); |
76 | va_end(args); | 87 | va_end(args); |
77 | 88 | ||