diff --git a/common/log.c b/common/log.c index ef791bec..018ba7ac 100644 --- a/common/log.c +++ b/common/log.c @@ -8,8 +8,6 @@ #include #include #include -#include -#include #include int colored = 1; @@ -90,32 +88,6 @@ void _sway_log(const char *filename, int line, log_importance_t verbosity, const } } -void sway_log_errno(log_importance_t verbosity, char* format, ...) { - if (verbosity <= v) { - unsigned int c = verbosity; - if (c > sizeof(verbosity_colors) / sizeof(char *) - 1) { - c = sizeof(verbosity_colors) / sizeof(char *) - 1; - } - - if (colored && isatty(STDERR_FILENO)) { - fprintf(stderr, "%s", verbosity_colors[c]); - } - - va_list args; - va_start(args, format); - vfprintf(stderr, format, args); - va_end(args); - - fprintf(stderr, ": "); - fprintf(stderr, "%s", strerror(errno)); - - if (colored && isatty(STDERR_FILENO)) { - fprintf(stderr, "\x1B[0m"); - } - fprintf(stderr, "\n"); - } -} - bool _sway_assert(bool condition, const char* format, ...) { if (condition) { return true; diff --git a/include/log.h b/include/log.h index efacf90f..266920f5 100644 --- a/include/log.h +++ b/include/log.h @@ -1,6 +1,8 @@ #ifndef _SWAY_LOG_H #define _SWAY_LOG_H #include +#include +#include typedef enum { L_SILENT = 0, @@ -15,7 +17,6 @@ void reset_log_level(void); // returns whether debug logging is on after switching. bool toggle_debug_logging(void); void sway_log_colors(int mode); -void sway_log_errno(log_importance_t verbosity, char* format, ...) __attribute__((format(printf,2,3))); void sway_abort(const char* format, ...) __attribute__((format(printf,1,2))); bool _sway_assert(bool condition, const char* format, ...) __attribute__((format(printf,2,3))); @@ -32,6 +33,9 @@ void _sway_log(const char *filename, int line, log_importance_t verbosity, const _sway_log(NULL, 0, VERBOSITY, FMT, ##__VA_ARGS__) #endif +#define sway_log_errno(VERBOSITY, FMT, ...) \ + _sway_log(NULL, 0, VERBOSITY, FMT ": %s", ##__VA_ARGS__, strerror(errno)) + void error_handler(int sig); #endif