aboutsummaryrefslogtreecommitdiff
path: root/sway/log.c
diff options
context:
space:
mode:
Diffstat (limited to 'sway/log.c')
-rw-r--r--sway/log.c30
1 files changed, 30 insertions, 0 deletions
diff --git a/sway/log.c b/sway/log.c
index 2d633abb..e8c1b78f 100644
--- a/sway/log.c
+++ b/sway/log.c
@@ -5,6 +5,8 @@
#include <fcntl.h>
#include <unistd.h>
#include <signal.h>
+#include <errno.h>
+#include <string.h>
int colored = 1;
int v = 0;
@@ -66,6 +68,34 @@ void sway_log(int verbosity, const char* format, ...) {
}
}
+void sway_log_errno(int verbosity, char* format, ...) {
+ if (verbosity <= v) {
+ int c = verbosity;
+ if (c > sizeof(verbosity_colors) / sizeof(char *)) {
+ c = sizeof(verbosity_colors) / sizeof(char *) - 1;
+ }
+
+ if (colored) {
+ fprintf(stderr, verbosity_colors[c]);
+ }
+
+ va_list args;
+ va_start(args, format);
+ vfprintf(stderr, format, args);
+ va_end(args);
+
+ fprintf(stderr, ": ");
+ char error[256];
+ strerror_r(errno, error, sizeof(error));
+ fprintf(stderr, error);
+
+ if (colored) {
+ fprintf(stderr, "\x1B[0m");
+ }
+ fprintf(stderr, "\n");
+ }
+}
+
bool sway_assert(bool condition, const char* format, ...) {
if (condition) {
return true;