From 9f02b0bf16972dfb7a18610e5096d4576e447a48 Mon Sep 17 00:00:00 2001 From: "S. Christoffer Eliesen" Date: Mon, 26 Oct 2015 13:41:45 +0100 Subject: commands: Learn 'debuglog'. Replicates i3 option. Verbosity level given as command line argument becomes default log level, and using 'debuglog toggle' switches back and forth between default and debug (or L_ERROR and debug if default is also L_DEBUG). --- sway/log.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'sway/log.c') diff --git a/sway/log.c b/sway/log.c index 62be73e5..2ad9657d 100644 --- a/sway/log.c +++ b/sway/log.c @@ -11,6 +11,7 @@ #include int colored = 1; +log_importance_t loglevel_default = L_ERROR; log_importance_t v = L_SILENT; static const char *verbosity_colors[] = { @@ -21,11 +22,29 @@ static const char *verbosity_colors[] = { }; void init_log(log_importance_t verbosity) { + if (verbosity != L_DEBUG) { + // command "debuglog" needs to know the user specified log level when + // turning off debug logging. + loglevel_default = verbosity; + } v = verbosity; signal(SIGSEGV, error_handler); signal(SIGABRT, error_handler); } +void set_log_level(log_importance_t verbosity) { + v = verbosity; +} + +void reset_log_level(void) { + v = loglevel_default; +} + +bool toggle_debug_logging(void) { + v = (v == L_DEBUG) ? loglevel_default : L_DEBUG; + return (v == L_DEBUG); +} + void sway_log_colors(int mode) { colored = (mode == 1) ? 1 : 0; } -- cgit v1.2.3