aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLibravatar Simon Ser <contact@emersion.fr>2020-12-02 14:57:48 +0100
committerLibravatar Tudor Brindus <me@tbrindus.ca>2020-12-09 23:57:12 -0500
commita68c6a00cae9a84ae0ac1f2c302afeb1b2f6142a (patch)
tree7a88fbe660110997c9c41d8975de0e3f605ae7b0
parentbuild: add basu as sd-bus provider (diff)
downloadsway-a68c6a00cae9a84ae0ac1f2c302afeb1b2f6142a.tar.gz
sway-a68c6a00cae9a84ae0ac1f2c302afeb1b2f6142a.tar.zst
sway-a68c6a00cae9a84ae0ac1f2c302afeb1b2f6142a.zip
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.c25
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) {
223 } 223 }
224} 224}
225 225
226static sway_log_importance_t convert_wlr_log_importance(
227 enum wlr_log_importance importance) {
228 switch (importance) {
229 case WLR_ERROR:
230 return SWAY_ERROR;
231 case WLR_INFO:
232 return SWAY_INFO;
233 default:
234 return SWAY_DEBUG;
235 }
236}
237
238static void handle_wlr_log(enum wlr_log_importance importance,
239 const char *fmt, va_list args) {
240 static char sway_fmt[1024];
241 snprintf(sway_fmt, sizeof(sway_fmt), "[wlr] %s", fmt);
242 _sway_vlog(convert_wlr_log_importance(importance), sway_fmt, args);
243}
244
226int main(int argc, char **argv) { 245int main(int argc, char **argv) {
227 static int verbose = 0, debug = 0, validate = 0, allow_unsupported_gpu = 0; 246 static int verbose = 0, debug = 0, validate = 0, allow_unsupported_gpu = 0;
228 247
@@ -315,13 +334,13 @@ int main(int argc, char **argv) {
315 // sway, we do not need to override it. 334 // sway, we do not need to override it.
316 if (debug) { 335 if (debug) {
317 sway_log_init(SWAY_DEBUG, sway_terminate); 336 sway_log_init(SWAY_DEBUG, sway_terminate);
318 wlr_log_init(WLR_DEBUG, NULL); 337 wlr_log_init(WLR_DEBUG, handle_wlr_log);
319 } else if (verbose) { 338 } else if (verbose) {
320 sway_log_init(SWAY_INFO, sway_terminate); 339 sway_log_init(SWAY_INFO, sway_terminate);
321 wlr_log_init(WLR_INFO, NULL); 340 wlr_log_init(WLR_INFO, handle_wlr_log);
322 } else { 341 } else {
323 sway_log_init(SWAY_ERROR, sway_terminate); 342 sway_log_init(SWAY_ERROR, sway_terminate);
324 wlr_log_init(WLR_ERROR, NULL); 343 wlr_log_init(WLR_ERROR, handle_wlr_log);
325 } 344 }
326 345
327 sway_log(SWAY_INFO, "Sway version " SWAY_VERSION); 346 sway_log(SWAY_INFO, "Sway version " SWAY_VERSION);