diff options
author | S. Christoffer Eliesen <christoffer@eliesen.no> | 2015-10-26 13:41:45 +0100 |
---|---|---|
committer | S. Christoffer Eliesen <christoffer@eliesen.no> | 2015-10-27 14:37:44 +0100 |
commit | 9f02b0bf16972dfb7a18610e5096d4576e447a48 (patch) | |
tree | b128d385d9c1889a9ad8e57751e3aab66c2994dc | |
parent | Merge pull request #204 from sce/misc_stuff (diff) | |
download | sway-9f02b0bf16972dfb7a18610e5096d4576e447a48.tar.gz sway-9f02b0bf16972dfb7a18610e5096d4576e447a48.tar.zst sway-9f02b0bf16972dfb7a18610e5096d4576e447a48.zip |
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).
-rw-r--r-- | include/log.h | 4 | ||||
-rw-r--r-- | sway.5.txt | 5 | ||||
-rw-r--r-- | sway/commands.c | 24 | ||||
-rw-r--r-- | sway/log.c | 19 |
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 | ||
13 | void init_log(log_importance_t verbosity); | 13 | void init_log(log_importance_t verbosity); |
14 | void set_log_level(log_importance_t verbosity); | ||
15 | void reset_log_level(void); | ||
16 | // returns whether debug logging is on after switching. | ||
17 | bool toggle_debug_logging(void); | ||
14 | void sway_log_colors(int mode); | 18 | void sway_log_colors(int mode); |
15 | void sway_log(log_importance_t verbosity, const char* format, ...) __attribute__((format(printf,2,3))); | 19 | void sway_log(log_importance_t verbosity, const char* format, ...) __attribute__((format(printf,2,3))); |
16 | void sway_log_errno(log_importance_t verbosity, char* format, ...) __attribute__((format(printf,2,3))); | 20 | void sway_log_errno(log_importance_t verbosity, char* format, ...) __attribute__((format(printf,2,3))); |
@@ -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 | ||
31 | static sway_cmd cmd_bindsym; | 31 | static sway_cmd cmd_bindsym; |
32 | static sway_cmd cmd_orientation; | 32 | static sway_cmd cmd_orientation; |
33 | static sway_cmd cmd_debuglog; | ||
33 | static sway_cmd cmd_exec; | 34 | static sway_cmd cmd_exec; |
34 | static sway_cmd cmd_exec_always; | 35 | static sway_cmd cmd_exec_always; |
35 | static sway_cmd cmd_exit; | 36 | static 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 | ||
233 | static 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 | |||
232 | static struct cmd_results *cmd_exec(int argc, char **argv) { | 255 | static 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 */ |
1163 | static struct cmd_handler handlers[] = { | 1186 | static 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 }, |
@@ -11,6 +11,7 @@ | |||
11 | #include <execinfo.h> | 11 | #include <execinfo.h> |
12 | 12 | ||
13 | int colored = 1; | 13 | int colored = 1; |
14 | log_importance_t loglevel_default = L_ERROR; | ||
14 | log_importance_t v = L_SILENT; | 15 | log_importance_t v = L_SILENT; |
15 | 16 | ||
16 | static const char *verbosity_colors[] = { | 17 | static const char *verbosity_colors[] = { |
@@ -21,11 +22,29 @@ static const char *verbosity_colors[] = { | |||
21 | }; | 22 | }; |
22 | 23 | ||
23 | void init_log(log_importance_t verbosity) { | 24 | void 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 | ||
35 | void set_log_level(log_importance_t verbosity) { | ||
36 | v = verbosity; | ||
37 | } | ||
38 | |||
39 | void reset_log_level(void) { | ||
40 | v = loglevel_default; | ||
41 | } | ||
42 | |||
43 | bool toggle_debug_logging(void) { | ||
44 | v = (v == L_DEBUG) ? loglevel_default : L_DEBUG; | ||
45 | return (v == L_DEBUG); | ||
46 | } | ||
47 | |||
29 | void sway_log_colors(int mode) { | 48 | void sway_log_colors(int mode) { |
30 | colored = (mode == 1) ? 1 : 0; | 49 | colored = (mode == 1) ? 1 : 0; |
31 | } | 50 | } |