aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDrew DeVault <sir@cmpwn.com>2016-05-02 13:50:08 -0400
committerDrew DeVault <sir@cmpwn.com>2016-05-02 13:50:08 -0400
commit93743e0d5f223d701ee934e61bfc7c2db4d24344 (patch)
treebb62675e504f73e2a1c1f71727256ae5f8e5bfa1
parent8a6b64e47109db52c74d0347ac7659e94a352ae6 (diff)
parentcc9d1cacbb79ce9a54f2c8505a25f4ace7d74c46 (diff)
downloadsway-93743e0d5f223d701ee934e61bfc7c2db4d24344.tar.xz
Merge pull request #632 from 1ace/refactor/log
Refactor preprocessor logic out of _sway_log()
-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, ...) {
sway_terminate(EXIT_FAILURE);
}
-#ifndef NDEBUG
void _sway_log(const char *filename, int line, log_importance_t verbosity, const char* format, ...) {
-#else
-void _sway_log(log_importance_t verbosity, const char* format, ...) {
-#endif
if (verbosity <= v) {
unsigned int c = verbosity;
if (c > sizeof(verbosity_colors) / sizeof(char *) - 1) {
@@ -76,13 +72,14 @@ void _sway_log(log_importance_t verbosity, const char* format, ...) {
fprintf(stderr, "%s", verbosity_colors[c]);
}
+ if (filename && line) {
+ char *file = strdup(filename);
+ fprintf(stderr, "[%s:%d] ", basename(file), line);
+ free(file);
+ }
+
va_list args;
va_start(args, format);
-#ifndef NDEBUG
- char *file = strdup(filename);
- fprintf(stderr, "[%s:%d] ", basename(file), line);
- free(file);
-#endif
vfprintf(stderr, format, args);
va_end(args);
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
#define sway_assert(COND, FMT, ...) \
_sway_assert(COND, "%s:" FMT, __PRETTY_FUNCTION__, ##__VA_ARGS__)
-#ifndef NDEBUG
void _sway_log(const char *filename, int line, log_importance_t verbosity, const char* format, ...) __attribute__((format(printf,4,5)));
+
+#ifndef NDEBUG
#define sway_log(VERBOSITY, FMT, ...) \
_sway_log(__FILE__, __LINE__, VERBOSITY, FMT, ##__VA_ARGS__)
#else
-void _sway_log(log_importance_t verbosity, const char* format, ...) __attribute__((format(printf,2,3)));
#define sway_log(VERBOSITY, FMT, ...) \
- _sway_log(VERBOSITY, FMT, ##__VA_ARGS__)
+ _sway_log(NULL, 0, VERBOSITY, FMT, ##__VA_ARGS__)
#endif
void error_handler(int sig);