aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorM Stoeckl <code@mstoeckl.com>2019-01-20 13:51:12 -0500
committeremersion <contact@emersion.fr>2019-01-21 12:59:42 +0100
commit1211a81aad18bbc4d9e8fb9973238ad8e7e1f688 (patch)
tree5c3f60e0219cb8b4a1b7cafb760a871661866e32
parent5c834d36e14aaeca4ac1d22b869254d5722af4af (diff)
Replace wlr_log with sway_log
This commit mostly duplicates the wlr_log functions, although with a sway_* prefix. (This is very similar to PR #2009.) However, the logging function no longer needs to be replaceable, so sway_log_init's second argument is used to set the exit callback for sway_abort. wlr_log_init is still invoked in sway/main.c This commit makes it easier to remove the wlroots dependency for the helper programs swaymsg, swaybg, swaybar, and swaynag.
-rw-r--r--common/background-image.c10
-rw-r--r--common/ipc-client.c2
-rw-r--r--common/log.c89
-rw-r--r--common/loop.c6
-rw-r--r--common/pango.c6
-rw-r--r--common/util.c4
-rw-r--r--include/log.h44
-rw-r--r--meson.build2
-rw-r--r--sway/commands.c16
-rw-r--r--sway/commands/assign.c2
-rw-r--r--sway/commands/bar.c8
-rw-r--r--sway/commands/bar/bind.c4
-rw-r--r--sway/commands/bar/binding_mode_indicator.c4
-rw-r--r--sway/commands/bar/font.c2
-rw-r--r--sway/commands/bar/gaps.c2
-rw-r--r--sway/commands/bar/height.c2
-rw-r--r--sway/commands/bar/hidden_state.c2
-rw-r--r--sway/commands/bar/icon_theme.c2
-rw-r--r--sway/commands/bar/id.c2
-rw-r--r--sway/commands/bar/mode.c2
-rw-r--r--sway/commands/bar/modifier.c2
-rw-r--r--sway/commands/bar/output.c2
-rw-r--r--sway/commands/bar/pango_markup.c4
-rw-r--r--sway/commands/bar/position.c2
-rw-r--r--sway/commands/bar/separator_symbol.c2
-rw-r--r--sway/commands/bar/status_command.c2
-rw-r--r--sway/commands/bar/status_edge_padding.c2
-rw-r--r--sway/commands/bar/status_padding.c2
-rw-r--r--sway/commands/bar/strip_workspace_name.c4
-rw-r--r--sway/commands/bar/strip_workspace_numbers.c4
-rw-r--r--sway/commands/bar/swaybar_command.c2
-rw-r--r--sway/commands/bar/tray_bind.c4
-rw-r--r--sway/commands/bar/tray_output.c4
-rw-r--r--sway/commands/bar/tray_padding.c2
-rw-r--r--sway/commands/bar/workspace_buttons.c4
-rw-r--r--sway/commands/bar/wrap_scroll.c4
-rw-r--r--sway/commands/bind.c8
-rw-r--r--sway/commands/client.c2
-rw-r--r--sway/commands/exec.c2
-rw-r--r--sway/commands/exec_always.c8
-rw-r--r--sway/commands/floating_minmax_size.c1
-rw-r--r--sway/commands/focus.c1
-rw-r--r--sway/commands/for_window.c2
-rw-r--r--sway/commands/input.c2
-rw-r--r--sway/commands/input/xkb_layout.c2
-rw-r--r--sway/commands/input/xkb_model.c2
-rw-r--r--sway/commands/input/xkb_options.c2
-rw-r--r--sway/commands/input/xkb_rules.c2
-rw-r--r--sway/commands/input/xkb_variant.c2
-rw-r--r--sway/commands/kill.c1
-rw-r--r--sway/commands/mode.c2
-rw-r--r--sway/commands/move.c15
-rw-r--r--sway/commands/output.c2
-rw-r--r--sway/commands/output/background.c8
-rw-r--r--sway/commands/reload.c2
-rw-r--r--sway/commands/rename.c2
-rw-r--r--sway/commands/resize.c1
-rw-r--r--sway/commands/scratchpad.c8
-rw-r--r--sway/commands/swap.c3
-rw-r--r--sway/commands/swaybg_command.c2
-rw-r--r--sway/commands/swaynag_command.c2
-rw-r--r--sway/commands/xwayland.c2
-rw-r--r--sway/config.c50
-rw-r--r--sway/config/bar.c14
-rw-r--r--sway/config/input.c18
-rw-r--r--sway/config/output.c44
-rw-r--r--sway/config/seat.c16
-rw-r--r--sway/criteria.c2
-rw-r--r--sway/debug-tree.c1
-rw-r--r--sway/desktop/idle_inhibit_v1.c4
-rw-r--r--sway/desktop/layer_shell.c9
-rw-r--r--sway/desktop/output.c4
-rw-r--r--sway/desktop/transaction.c14
-rw-r--r--sway/desktop/xdg_shell.c4
-rw-r--r--sway/desktop/xdg_shell_v6.c4
-rw-r--r--sway/desktop/xwayland.c10
-rw-r--r--sway/input/cursor.c4
-rw-r--r--sway/input/input-manager.c84
-rw-r--r--sway/input/keyboard.c10
-rw-r--r--sway/input/seat.c32
-rw-r--r--sway/ipc-server.c70
-rw-r--r--sway/main.c39
-rw-r--r--sway/server.c18
-rw-r--r--sway/swaynag.c8
-rw-r--r--sway/tree/arrange.c8
-rw-r--r--sway/tree/container.c6
-rw-r--r--sway/tree/output.c10
-rw-r--r--sway/tree/root.c14
-rw-r--r--sway/tree/view.c14
-rw-r--r--sway/tree/workspace.c18
-rw-r--r--swaybar/bar.c7
-rw-r--r--swaybar/config.c4
-rw-r--r--swaybar/i3bar.c14
-rw-r--r--swaybar/input.c3
-rw-r--r--swaybar/ipc.c14
-rw-r--r--swaybar/main.c10
-rw-r--r--swaybar/render.c1
-rw-r--r--swaybar/status_line.c18
-rw-r--r--swaybar/tray/host.c30
-rw-r--r--swaybar/tray/icon.c2
-rw-r--r--swaybar/tray/item.c40
-rw-r--r--swaybar/tray/tray.c10
-rw-r--r--swaybar/tray/watcher.c26
-rw-r--r--swaybg/main.c14
-rw-r--r--swaymsg/main.c4
-rw-r--r--swaynag/main.c20
-rw-r--r--swaynag/render.c2
-rw-r--r--swaynag/swaynag.c20
108 files changed, 610 insertions, 501 deletions
diff --git a/common/background-image.c b/common/background-image.c
index 72f39a79..d15c2989 100644
--- a/common/background-image.c
+++ b/common/background-image.c
@@ -1,8 +1,8 @@
#include <assert.h>
#include <stdbool.h>
-#include <wlr/util/log.h>
#include "background-image.h"
#include "cairo.h"
+#include "log.h"
enum background_mode parse_background_mode(const char *mode) {
if (strcmp(mode, "stretch") == 0) {
@@ -18,7 +18,7 @@ enum background_mode parse_background_mode(const char *mode) {
} else if (strcmp(mode, "solid_color") == 0) {
return BACKGROUND_MODE_SOLID_COLOR;
}
- wlr_log(WLR_ERROR, "Unsupported background mode: %s", mode);
+ sway_log(SWAY_ERROR, "Unsupported background mode: %s", mode);
return BACKGROUND_MODE_INVALID;
}
@@ -28,7 +28,7 @@ cairo_surface_t *load_background_image(const char *path) {
GError *err = NULL;
GdkPixbuf *pixbuf = gdk_pixbuf_new_from_file(path, &err);
if (!pixbuf) {
- wlr_log(WLR_ERROR, "Failed to load background image (%s).",
+ sway_log(SWAY_ERROR, "Failed to load background image (%s).",
err->message);
return false;
}
@@ -38,11 +38,11 @@ cairo_surface_t *load_background_image(const char *path) {
image = cairo_image_surface_create_from_png(path);
#endif // HAVE_GDK_PIXBUF
if (!image) {
- wlr_log(WLR_ERROR, "Failed to read background image.");
+ sway_log(SWAY_ERROR, "Failed to read background image.");
return NULL;
}
if (cairo_surface_status(image) != CAIRO_STATUS_SUCCESS) {
- wlr_log(WLR_ERROR, "Failed to read background image: %s."
+ sway_log(SWAY_ERROR, "Failed to read background image: %s."
#if !HAVE_GDK_PIXBUF
"\nSway was compiled without gdk_pixbuf support, so only"
"\nPNG images can be loaded. This is the likely cause."
diff --git a/common/ipc-client.c b/common/ipc-client.c
index 79ed3555..13e2dfa3 100644
--- a/common/ipc-client.c
+++ b/common/ipc-client.c
@@ -111,7 +111,7 @@ error_2:
free(response);
free(payload);
error_1:
- wlr_log(WLR_ERROR, "Unable to allocate memory for IPC response");
+ sway_log(SWAY_ERROR, "Unable to allocate memory for IPC response");
return NULL;
}
diff --git a/common/log.c b/common/log.c
index 847f3952..669fd360 100644
--- a/common/log.c
+++ b/common/log.c
@@ -1,16 +1,20 @@
+#define _POSIX_C_SOURCE 199506L
#include <signal.h>
#include <stdarg.h>
+#include <stdio.h>
#include <stdlib.h>
+#include <time.h>
+#include <unistd.h>
#include "log.h"
-void sway_terminate(int code);
+static terminate_callback_t log_terminate = exit;
void _sway_abort(const char *format, ...) {
va_list args;
va_start(args, format);
- _wlr_vlog(WLR_ERROR, format, args);
+ _sway_vlog(SWAY_ERROR, format, args);
va_end(args);
- sway_terminate(EXIT_FAILURE);
+ log_terminate(EXIT_FAILURE);
}
bool _sway_assert(bool condition, const char *format, ...) {
@@ -20,7 +24,7 @@ bool _sway_assert(bool condition, const char *format, ...) {
va_list args;
va_start(args, format);
- _wlr_vlog(WLR_ERROR, format, args);
+ _sway_vlog(SWAY_ERROR, format, args);
va_end(args);
#ifndef NDEBUG
@@ -29,3 +33,80 @@ bool _sway_assert(bool condition, const char *format, ...) {
return false;
}
+
+static bool colored = true;
+static sway_log_importance_t log_importance = SWAY_ERROR;
+
+static const char *verbosity_colors[] = {
+ [SWAY_SILENT] = "",
+ [SWAY_ERROR ] = "\x1B[1;31m",
+ [SWAY_INFO ] = "\x1B[1;34m",
+ [SWAY_DEBUG ] = "\x1B[1;30m",
+};
+
+static void sway_log_stderr(sway_log_importance_t verbosity, const char *fmt,
+ va_list args) {
+ if (verbosity > log_importance) {
+ return;
+ }
+ // prefix the time to the log message
+ struct tm result;
+ time_t t = time(NULL);
+ struct tm *tm_info = localtime_r(&t, &result);
+ char buffer[26];
+
+ // generate time prefix
+ strftime(buffer, sizeof(buffer), "%F %T - ", tm_info);
+ fprintf(stderr, "%s", buffer);
+
+ unsigned c = (verbosity < SWAY_LOG_IMPORTANCE_LAST) ? verbosity :
+ SWAY_LOG_IMPORTANCE_LAST - 1;
+
+ if (colored && isatty(STDERR_FILENO)) {
+ fprintf(stderr, "%s", verbosity_colors[c]);
+ }
+
+ vfprintf(stderr, fmt, args);
+
+ if (colored && isatty(STDERR_FILENO)) {
+ fprintf(stderr, "\x1B[0m");
+ }
+ fprintf(stderr, "\n");
+}
+
+void sway_log_init(sway_log_importance_t verbosity, terminate_callback_t callback) {
+ if (verbosity < SWAY_LOG_IMPORTANCE_LAST) {
+ log_importance = verbosity;
+ }
+ if (callback) {
+ log_terminate = callback;
+ }
+}
+
+void _sway_vlog(sway_log_importance_t verbosity, const char *fmt, va_list args) {
+ sway_log_stderr(verbosity, fmt, args);
+}
+
+void _sway_log(sway_log_importance_t verbosity, const char *fmt, ...) {
+ va_list args;
+ va_start(args, fmt);
+ sway_log_stderr(verbosity, fmt, args);
+ va_end(args);
+}
+
+// strips the path prefix from filepath
+// will try to strip SWAY_SRC_DIR as well as a relative src dir
+// e.g. '/src/build/sway/util/log.c' and
+// '../util/log.c' will both be stripped to
+// 'util/log.c'
+const char *_sway_strip_path(const char *filepath) {
+ static int srclen = sizeof(SWAY_SRC_DIR);
+ if (strstr(filepath, SWAY_SRC_DIR) == filepath) {
+ filepath += srclen;
+ } else if (*filepath == '.') {
+ while (*filepath == '.' || *filepath == '/') {
+ ++filepath;
+ }
+ }
+ return filepath;
+}
diff --git a/common/loop.c b/common/loop.c
index 295f3a30..aecad2f3 100644
--- a/common/loop.c
+++ b/common/loop.c
@@ -34,7 +34,7 @@ struct loop {
struct loop *loop_create(void) {
struct loop *loop = calloc(1, sizeof(struct loop));
if (!loop) {
- wlr_log(WLR_ERROR, "Unable to allocate memory for loop");
+ sway_log(SWAY_ERROR, "Unable to allocate memory for loop");
return NULL;
}
loop->fd_capacity = 10;
@@ -107,7 +107,7 @@ void loop_add_fd(struct loop *loop, int fd, short mask,
void (*callback)(int fd, short mask, void *data), void *data) {
struct loop_fd_event *event = calloc(1, sizeof(struct loop_fd_event));
if (!event) {
- wlr_log(WLR_ERROR, "Unable to allocate memory for event");
+ sway_log(SWAY_ERROR, "Unable to allocate memory for event");
return;
}
event->callback = callback;
@@ -129,7 +129,7 @@ struct loop_timer *loop_add_timer(struct loop *loop, int ms,
void (*callback)(void *data), void *data) {
struct loop_timer *timer = calloc(1, sizeof(struct loop_timer));
if (!timer) {
- wlr_log(WLR_ERROR, "Unable to allocate memory for timer");
+ sway_log(SWAY_ERROR, "Unable to allocate memory for timer");
return NULL;
}
timer->callback = callback;
diff --git a/common/pango.c b/common/pango.c
index 7e164043..fc3d0688 100644
--- a/common/pango.c
+++ b/common/pango.c
@@ -61,7 +61,7 @@ PangoLayout *get_pango_layout(cairo_t *cairo, const char