aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--include/log.h4
-rw-r--r--sway.5.txt5
-rw-r--r--sway/commands.c24
-rw-r--r--sway/log.c19
4 files changed, 52 insertions, 0 deletions
diff --git a/include/log.h b/include/log.h
index 806725a6..4b769c93 100644
--- a/include/log.h
+++ b/include/log.h
@@ -11,6 +11,10 @@ typedef enum {
11} log_importance_t; 11} log_importance_t;
12 12
13void init_log(log_importance_t verbosity); 13void init_log(log_importance_t verbosity);
14void set_log_level(log_importance_t verbosity);
15void reset_log_level(void);
16// returns whether debug logging is on after switching.
17bool toggle_debug_logging(void);
14void sway_log_colors(int mode); 18void sway_log_colors(int mode);
15void sway_log(log_importance_t verbosity, const char* format, ...) __attribute__((format(printf,2,3))); 19void sway_log(log_importance_t verbosity, const char* format, ...) __attribute__((format(printf,2,3)));
16void sway_log_errno(log_importance_t verbosity, char* format, ...) __attribute__((format(printf,2,3))); 20void sway_log_errno(log_importance_t verbosity, char* format, ...) __attribute__((format(printf,2,3)));
diff --git a/sway.5.txt b/sway.5.txt
index d97720c5..69a6909f 100644
--- a/sway.5.txt
+++ b/sway.5.txt
@@ -28,6 +28,11 @@ Commands
28 execute Firefox if the alt, shift, and F keys are pressed together. Any 28 execute Firefox if the alt, shift, and F keys are pressed together. Any
29 valid sway command is eligible to be bound to a key combo. 29 valid sway command is eligible to be bound to a key combo.
30 30
31**debuglog** <on|off|toggle>::
32 Turn debug log output _on_ or _off_. This will override any command line
33 option given. _toggle_ will toggle between debug and log level given as
34 command line option.
35
31**exec** <shell command>:: 36**exec** <shell command>::
32 Executes _shell command_ with sh. 37 Executes _shell command_ with sh.
33 38
diff --git a/sway/commands.c b/sway/commands.c
index 0102fc5a..c81379fd 100644
--- a/sway/commands.c
+++ b/sway/commands.c
@@ -30,6 +30,7 @@ struct cmd_handler {
30 30
31static sway_cmd cmd_bindsym; 31static sway_cmd cmd_bindsym;
32static sway_cmd cmd_orientation; 32static sway_cmd cmd_orientation;
33static sway_cmd cmd_debuglog;
33static sway_cmd cmd_exec; 34static sway_cmd cmd_exec;
34static sway_cmd cmd_exec_always; 35static sway_cmd cmd_exec_always;
35static sway_cmd cmd_exit; 36static sway_cmd cmd_exit;
@@ -229,6 +230,28 @@ static struct cmd_results *cmd_exec_always(int argc, char **argv) {
229 return cmd_results_new(CMD_SUCCESS, NULL, NULL); 230 return cmd_results_new(CMD_SUCCESS, NULL, NULL);
230} 231}
231 232
233static struct cmd_results *cmd_debuglog(int argc, char **argv) {
234 struct cmd_results *error = NULL;
235 if ((error = checkarg(argc, "debuglog", EXPECTED_EQUAL_TO, 1))) {
236 return error;
237 } else if (strcasecmp(argv[0], "toggle") == 0) {
238 if (config->reading) {
239 return cmd_results_new(CMD_FAILURE, "debuglog toggle", "Can't be used in config file.");
240 }
241 if (toggle_debug_logging()) {
242 sway_log(L_DEBUG, "Debuglog turned on.");
243 }
244 } else if (strcasecmp(argv[0], "on") == 0) {
245 set_log_level(L_DEBUG);
246 sway_log(L_DEBUG, "Debuglog turned on.");
247 } else if (strcasecmp(argv[0], "off") == 0) {
248 reset_log_level();
249 } else {
250 return cmd_results_new(CMD_FAILURE, "debuglog", "Expected 'debuglog on|off|toggle'");
251 }
252 return cmd_results_new(CMD_SUCCESS, NULL, NULL);
253}
254
232static struct cmd_results *cmd_exec(int argc, char **argv) { 255static struct cmd_results *cmd_exec(int argc, char **argv) {
233 if (!config->active) return cmd_results_new(CMD_DEFER, "exec", NULL); 256 if (!config->active) return cmd_results_new(CMD_DEFER, "exec", NULL);
234 if (config->reloading) { 257 if (config->reloading) {
@@ -1162,6 +1185,7 @@ static struct cmd_results *cmd_ws_auto_back_and_forth(int argc, char **argv) {
1162/* Keep alphabetized */ 1185/* Keep alphabetized */
1163static struct cmd_handler handlers[] = { 1186static struct cmd_handler handlers[] = {
1164 { "bindsym", cmd_bindsym }, 1187 { "bindsym", cmd_bindsym },
1188 { "debuglog", cmd_debuglog },
1165 { "default_orientation", cmd_orientation }, 1189 { "default_orientation", cmd_orientation },
1166 { "exec", cmd_exec }, 1190 { "exec", cmd_exec },
1167 { "exec_always", cmd_exec_always }, 1191 { "exec_always", cmd_exec_always },
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 @@
11#include <execinfo.h> 11#include <execinfo.h>
12 12
13int colored = 1; 13int colored = 1;
14log_importance_t loglevel_default = L_ERROR;
14log_importance_t v = L_SILENT; 15log_importance_t v = L_SILENT;
15 16
16static const char *verbosity_colors[] = { 17static const char *verbosity_colors[] = {
@@ -21,11 +22,29 @@ static const char *verbosity_colors[] = {
21}; 22};
22 23
23void init_log(log_importance_t verbosity) { 24void init_log(log_importance_t verbosity) {
25 if (verbosity != L_DEBUG) {
26 // command "debuglog" needs to know the user specified log level when
27 // turning off debug logging.
28 loglevel_default = verbosity;
29 }
24 v = verbosity; 30 v = verbosity;
25 signal(SIGSEGV, error_handler); 31 signal(SIGSEGV, error_handler);
26 signal(SIGABRT, error_handler); 32 signal(SIGABRT, error_handler);
27} 33}
28 34
35void set_log_level(log_importance_t verbosity) {
36 v = verbosity;
37}
38
39void reset_log_level(void) {
40 v = loglevel_default;
41}
42
43bool toggle_debug_logging(void) {
44 v = (v == L_DEBUG) ? loglevel_default : L_DEBUG;
45 return (v == L_DEBUG);
46}
47
29void sway_log_colors(int mode) { 48void sway_log_colors(int mode) {
30 colored = (mode == 1) ? 1 : 0; 49 colored = (mode == 1) ? 1 : 0;
31} 50}