aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--common/log.c15
-rw-r--r--include/log.h6
2 files changed, 9 insertions, 12 deletions
diff --git a/common/log.c b/common/log.c
index c5c9f3a6..ef791bec 100644
--- a/common/log.c
+++ b/common/log.c
@@ -61,11 +61,7 @@ void sway_abort(const char *format, ...) {
61 sway_terminate(EXIT_FAILURE); 61 sway_terminate(EXIT_FAILURE);
62} 62}
63 63
64#ifndef NDEBUG
65void _sway_log(const char *filename, int line, log_importance_t verbosity, const char* format, ...) { 64void _sway_log(const char *filename, int line, log_importance_t verbosity, const char* format, ...) {
66#else
67void _sway_log(log_importance_t verbosity, const char* format, ...) {
68#endif
69 if (verbosity <= v) { 65 if (verbosity <= v) {
70 unsigned int c = verbosity; 66 unsigned int c = verbosity;
71 if (c > sizeof(verbosity_colors) / sizeof(char *) - 1) { 67 if (c > sizeof(verbosity_colors) / sizeof(char *) - 1) {
@@ -76,13 +72,14 @@ void _sway_log(log_importance_t verbosity, const char* format, ...) {
76 fprintf(stderr, "%s", verbosity_colors[c]); 72 fprintf(stderr, "%s", verbosity_colors[c]);
77 } 73 }
78 74
75 if (filename && line) {
76 char *file = strdup(filename);
77 fprintf(stderr, "[%s:%d] ", basename(file), line);
78 free(file);
79 }
80
79 va_list args; 81 va_list args;
80 va_start(args, format); 82 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
86 vfprintf(stderr, format, args); 83 vfprintf(stderr, format, args);
87 va_end(args); 84 va_end(args);
88 85
diff --git a/include/log.h b/include/log.h
index 268783f4..efacf90f 100644
--- a/include/log.h
+++ b/include/log.h
@@ -22,14 +22,14 @@ bool _sway_assert(bool condition, const char* format, ...) __attribute__((format
22#define sway_assert(COND, FMT, ...) \ 22#define sway_assert(COND, FMT, ...) \
23 _sway_assert(COND, "%s:" FMT, __PRETTY_FUNCTION__, ##__VA_ARGS__) 23 _sway_assert(COND, "%s:" FMT, __PRETTY_FUNCTION__, ##__VA_ARGS__)
24 24
25#ifndef NDEBUG
26void _sway_log(const char *filename, int line, log_importance_t verbosity, const char* format, ...) __attribute__((format(printf,4,5))); 25void _sway_log(const char *filename, int line, log_importance_t verbosity, const char* format, ...) __attribute__((format(printf,4,5)));
26
27#ifndef NDEBUG
27#define sway_log(VERBOSITY, FMT, ...) \ 28#define sway_log(VERBOSITY, FMT, ...) \
28 _sway_log(__FILE__, __LINE__, VERBOSITY, FMT, ##__VA_ARGS__) 29 _sway_log(__FILE__, __LINE__, VERBOSITY, FMT, ##__VA_ARGS__)
29#else 30#else
30void _sway_log(log_importance_t verbosity, const char* format, ...) __attribute__((format(printf,2,3)));
31#define sway_log(VERBOSITY, FMT, ...) \ 31#define sway_log(VERBOSITY, FMT, ...) \
32 _sway_log(VERBOSITY, FMT, ##__VA_ARGS__) 32 _sway_log(NULL, 0, VERBOSITY, FMT, ##__VA_ARGS__)
33#endif 33#endif
34 34
35void error_handler(int sig); 35void error_handler(int sig);