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 | |
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
-rw-r--r-- | include/log.h | 11 | ||||
-rw-r--r-- | sway/log.c | 13 |
2 files changed, 22 insertions, 2 deletions
diff --git a/include/log.h b/include/log.h index 4b769c93..eada025e 100644 --- a/include/log.h +++ b/include/log.h | |||
@@ -16,7 +16,6 @@ void reset_log_level(void); | |||
16 | // returns whether debug logging is on after switching. | 16 | // returns whether debug logging is on after switching. |
17 | bool toggle_debug_logging(void); | 17 | bool toggle_debug_logging(void); |
18 | void sway_log_colors(int mode); | 18 | void sway_log_colors(int mode); |
19 | void sway_log(log_importance_t verbosity, const char* format, ...) __attribute__((format(printf,2,3))); | ||
20 | void sway_log_errno(log_importance_t verbosity, char* format, ...) __attribute__((format(printf,2,3))); | 19 | void sway_log_errno(log_importance_t verbosity, char* format, ...) __attribute__((format(printf,2,3))); |
21 | void sway_abort(const char* format, ...) __attribute__((format(printf,1,2))); | 20 | void sway_abort(const char* format, ...) __attribute__((format(printf,1,2))); |
22 | 21 | ||
@@ -24,6 +23,16 @@ bool _sway_assert(bool condition, const char* format, ...) __attribute__((format | |||
24 | #define sway_assert(COND, FMT, ...) \ | 23 | #define sway_assert(COND, FMT, ...) \ |
25 | _sway_assert(COND, "%s:" FMT, __PRETTY_FUNCTION__, ##__VA_ARGS__) | 24 | _sway_assert(COND, "%s:" FMT, __PRETTY_FUNCTION__, ##__VA_ARGS__) |
26 | 25 | ||
26 | #ifndef NDEBUG | ||
27 | void _sway_log(const char *filename, int line, log_importance_t verbosity, const char* format, ...) __attribute__((format(printf,4,5))); | ||
28 | #define sway_log(VERBOSITY, FMT, ...) \ | ||
29 | _sway_log(__FILE__, __LINE__, VERBOSITY, FMT, ##__VA_ARGS__) | ||
30 | #else | ||
31 | void _sway_log(log_importance_t verbosity, const char* format, ...) __attribute__((format(printf,2,3))); | ||
32 | #define sway_log(VERBOSITY, FMT, ...) \ | ||
33 | _sway_log(VERBOSITY, FMT, ##__VA_ARGS__) | ||
34 | #endif | ||
35 | |||
27 | void error_handler(int sig); | 36 | void error_handler(int sig); |
28 | 37 | ||
29 | void layout_log(const swayc_t *c, int depth); | 38 | void layout_log(const swayc_t *c, int depth); |
@@ -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 | ||