diff options
author | Simon Ser <contact@emersion.fr> | 2020-12-02 14:57:48 +0100 |
---|---|---|
committer | Tudor Brindus <me@tbrindus.ca> | 2020-12-09 23:57:12 -0500 |
commit | a68c6a00cae9a84ae0ac1f2c302afeb1b2f6142a (patch) | |
tree | 7a88fbe660110997c9c41d8975de0e3f605ae7b0 | |
parent | a52176f83035e98dd5487e3373ee2c52c8890c8d (diff) |
Route wlroots logs into Sway logging infrastructure
Instead of letting wlroots print messages to stdout, route debugging
messages into Sway's logging functions. This allows a more consistent
output (e.g. if Sway or wlroots changes its output style, they don't get
out-of-sync).
I also added a [wlr] prefix to wlroots messages, not yet sure it's a
good thing.
-rw-r--r-- | sway/main.c | 25 |
1 files changed, 22 insertions, 3 deletions
diff --git a/sway/main.c b/sway/main.c index cd03c873..62a88835 100644 --- a/sway/main.c +++ b/sway/main.c @@ -223,6 +223,25 @@ void enable_debug_flag(const char *flag) { } } +static sway_log_importance_t convert_wlr_log_importance( + enum wlr_log_importance importance) { + switch (importance) { + case WLR_ERROR: + return SWAY_ERROR; + case WLR_INFO: + return SWAY_INFO; + default: + return SWAY_DEBUG; + } +} + +static void handle_wlr_log(enum wlr_log_importance importance, + const char *fmt, va_list args) { + static char sway_fmt[1024]; + snprintf(sway_fmt, sizeof(sway_fmt), "[wlr] %s", fmt); + _sway_vlog(convert_wlr_log_importance(importance), sway_fmt, args); +} + int main(int argc, char **argv) { static int verbose = 0, debug = 0, validate = 0, allow_unsupported_gpu = 0; @@ -315,13 +334,13 @@ int main(int argc, char **argv) { // sway, we do not need to override it. if (debug) { sway_log_init(SWAY_DEBUG, sway_terminate); - wlr_log_init(WLR_DEBUG, NULL); + wlr_log_init(WLR_DEBUG, handle_wlr_log); } else if (verbose) { sway_log_init(SWAY_INFO, sway_terminate); - wlr_log_init(WLR_INFO, NULL); + wlr_log_init(WLR_INFO, handle_wlr_log); } else { sway_log_init(SWAY_ERROR, sway_terminate); - wlr_log_init(WLR_ERROR, NULL); + wlr_log_init(WLR_ERROR, handle_wlr_log); } sway_log(SWAY_INFO, "Sway version " SWAY_VERSION); |