Implement debuglog command
Patch status: superseded
Patch by Alexander Berntsen
Long description:
Add debuglog command that takes toggle|on|off. Add get_debug_logging() to be able to toggle. Make t/187-commands-parser.t expect 'debuglog'. Document the debuglog command in userguide.
To apply this patch, use:
curl http://cr.i3wm.org/patch/185/raw.patch | git am
b/docs/userguide
22 |
@@ -1762,6 +1762,8 @@ stack-limit rows 5 |
23 |
image:stacklimit.png[Container limited to two columns] |
24 |
/////////////////////////////////////////////////////////////////////////////// |
25 |
|
26 |
+[[shmlog]] |
27 |
+ |
28 |
=== Enabling shared memory logging |
29 |
|
30 |
As described in http://i3wm.org/docs/debugging.html, i3 can log to a shared |
31 |
@@ -1787,6 +1789,24 @@ bindsym $mod+x shmlog toggle |
32 |
i3-msg shmlog $((50*1024*1024)) |
33 |
--------------- |
34 |
|
35 |
+=== Enabling debug logging |
36 |
+ |
37 |
+The +debuglog+ command allows you to enable or disable debug logging at |
38 |
+runtime. Debug logging is much more verbose than non-debug logging. This |
39 |
+command does not activate shared memory logging (shmlog), and as such is most |
40 |
+likely useful in combination with the above-described <<shmlog>> command. |
41 |
+ |
42 |
+*Syntax*: |
43 |
+------------------------ |
44 |
+debuglog <on|off|toggle> |
45 |
+------------------------ |
46 |
+ |
47 |
+*Examples*: |
48 |
+------------ |
49 |
+# Enable/disable logging |
50 |
+bindsym $mod+x debuglog toggle |
51 |
+------------ |
52 |
+ |
53 |
=== Reloading/Restarting/Exiting |
54 |
|
55 |
You can make i3 reload its configuration file with +reload+. You can also |
b/include/commands.h
60 |
@@ -277,4 +277,10 @@ void cmd_bar(I3_CMD, char *bar_type, char *bar_value, char *bar_id); |
61 |
*/ |
62 |
void cmd_shmlog(I3_CMD, char *argument); |
63 |
|
64 |
+/* |
65 |
+ * Implementation of 'debuglog toggle|on|off' |
66 |
+ * |
67 |
+ */ |
68 |
+void cmd_debuglog(I3_CMD, char *argument); |
69 |
+ |
70 |
#endif |
b/include/log.h
75 |
@@ -51,6 +51,12 @@ void open_logbuffer(void); |
76 |
void close_logbuffer(void); |
77 |
|
78 |
/** |
79 |
+ * Checks if debug logging is active. |
80 |
+ * |
81 |
+ */ |
82 |
+bool get_debug_logging(void); |
83 |
+ |
84 |
+/** |
85 |
* Set debug logging. |
86 |
* |
87 |
*/ |
b/parser-specs/commands.spec
92 |
@@ -20,6 +20,7 @@ state INITIAL: |
93 |
'restart' -> call cmd_restart() |
94 |
'reload' -> call cmd_reload() |
95 |
'shmlog' -> SHMLOG |
96 |
+ 'debuglog' -> DEBUGLOG |
97 |
'border' -> BORDER |
98 |
'layout' -> LAYOUT |
99 |
'append_layout' -> APPEND_LAYOUT |
100 |
@@ -69,6 +70,11 @@ state SHMLOG: |
101 |
argument = string |
102 |
-> call cmd_shmlog($argument) |
103 |
|
104 |
+# debuglog toggle|on|off |
105 |
+state DEBUGLOG: |
106 |
+ argument = 'toggle', 'on', 'off' |
107 |
+ -> call cmd_debuglog($argument) |
108 |
+ |
109 |
# border normal|none|1pixel|toggle|1pixel |
110 |
state BORDER: |
111 |
border_style = 'normal', 'pixel' |
b/src/commands.c
116 |
@@ -2059,3 +2059,23 @@ void cmd_shmlog(I3_CMD, char *argument) { |
117 |
// XXX: default reply for now, make this a better reply |
118 |
ysuccess(true); |
119 |
} |
120 |
+ |
121 |
+/* |
122 |
+ * Implementation of 'debuglog toggle|on|off' |
123 |
+ * |
124 |
+ */ |
125 |
+void cmd_debuglog(I3_CMD, char *argument) { |
126 |
+ bool logging = get_debug_logging(); |
127 |
+ if (!strcmp(argument,"toggle")) { |
128 |
+ LOG("%s debug logging\n", logging ? "Disabling" : "Enabling"); |
129 |
+ set_debug_logging(!get_debug_logging()); |
130 |
+ } else if (!strcmp(argument, "on") && !logging) { |
131 |
+ LOG("Enabling debug logging\n"); |
132 |
+ set_debug_logging(true); |
133 |
+ } else if (!strcmp(argument, "off") && logging) { |
134 |
+ LOG("Disabling debug logging\n"); |
135 |
+ set_debug_logging(false); |
136 |
+ } |
137 |
+ // XXX: default reply for now, make this a better reply |
138 |
+ ysuccess(true); |
139 |
+} |
b/src/log.c
144 |
@@ -181,6 +181,14 @@ void set_verbosity(bool _verbose) { |
145 |
} |
146 |
|
147 |
/* |
148 |
+ * Get debug logging. |
149 |
+ * |
150 |
+ */ |
151 |
+bool get_debug_logging(void) { |
152 |
+ return debug_logging; |
153 |
+} |
154 |
+ |
155 |
+/* |
156 |
* Set debug logging. |
157 |
* |
158 |
*/ |
b/testcases/t/187-commands-parser.t
163 |
@@ -144,7 +144,7 @@ is(parser_calls("\nworkspace test"), |
164 |
################################################################################ |
165 |
|
166 |
is(parser_calls('unknown_literal'), |
167 |
- "ERROR: Expected one of these tokens: <end>, '[', 'move', 'exec', 'exit', 'restart', 'reload', 'shmlog', 'border', 'layout', 'append_layout', 'workspace', 'focus', 'kill', 'open', 'fullscreen', 'split', 'floating', 'mark', 'resize', 'rename', 'nop', 'scratchpad', 'mode', 'bar'\n" . |
168 |
+ "ERROR: Expected one of these tokens: <end>, '[', 'move', 'exec', 'exit', 'restart', 'reload', 'shmlog', 'debuglog', 'border', 'layout', 'append_layout', 'workspace', 'focus', 'kill', 'open', 'fullscreen', 'split', 'floating', 'mark', 'resize', 'rename', 'nop', 'scratchpad', 'mode', 'bar'\n" . |
169 |
"ERROR: Your command: unknown_literal\n" . |
170 |
"ERROR: ^^^^^^^^^^^^^^^", |
171 |
'error for unknown literal ok'); |