i3 - improved tiling WM


Implement debuglog command

Patch status: rejected

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/183/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,25 @@ bindsym $mod+x shmlog toggle
32
 i3-msg shmlog $((50*1024*1024))
33
 ---------------
34
 
35
+=== Enabling debug logging
36
+
37
+The above-described <<shmlog>> may log to STDOUT while prefixing the current
38
+time to it, if debug logging is activated. The +debuglog+ command
39
+allows you to enable or disable debug logging at runtime.
40
+
41
+*Syntax*:
42
+------------------------
43
+debuglog <on|off|toggle>
44
+------------------------
45
+
46
+*Examples*:
47
+------------
48
+# Enable/disable logging
49
+bindsym $mod-shift-x debuglog toggle
50
+# or, from terminal:
51
+i3-msg debug on
52
+------------
53
+
54
 === Reloading/Restarting/Exiting
55
 
56
 You can make i3 reload its configuration file with +reload+. You can also

b/include/commands.h

61
@@ -277,4 +277,10 @@ void cmd_bar(I3_CMD, char *bar_type, char *bar_value, char *bar_id);
62
  */
63
 void cmd_shmlog(I3_CMD, char *argument);
64
 
65
+/*
66
+ * Implementation of 'debuglog toggle|on|off'
67
+ *
68
+ */
69
+void cmd_debuglog(I3_CMD, char *argument);
70
+
71
 #endif

b/include/log.h

76
@@ -51,6 +51,12 @@ void open_logbuffer(void);
77
 void close_logbuffer(void);
78
 
79
 /**
80
+ * Checks if debug logging is active.
81
+ *
82
+ */
83
+bool get_debug_logging(void);
84
+
85
+/**
86
  * Set debug logging.
87
  *
88
  */

b/parser-specs/commands.spec

93
@@ -20,6 +20,7 @@ state INITIAL:
94
   'restart' -> call cmd_restart()
95
   'reload' -> call cmd_reload()
96
   'shmlog' -> SHMLOG
97
+  'debuglog' -> DEBUGLOG
98
   'border' -> BORDER
99
   'layout' -> LAYOUT
100
   'append_layout' -> APPEND_LAYOUT
101
@@ -69,6 +70,11 @@ state SHMLOG:
102
   argument = string
103
     -> call cmd_shmlog($argument)
104
 
105
+# debuglog toggle|on|off
106
+state DEBUGLOG:
107
+  argument = 'toggle', 'on', 'off'
108
+    -> call cmd_debuglog($argument)
109
+
110
 # border normal|none|1pixel|toggle|1pixel
111
 state BORDER:
112
   border_style = 'normal', 'pixel'

b/src/commands.c

117
@@ -2059,3 +2059,19 @@ void cmd_shmlog(I3_CMD, char *argument) {
118
     // XXX: default reply for now, make this a better reply
119
     ysuccess(true);
120
 }
121
+
122
+/*
123
+ * Implementation of 'debuglog toggle|on|off'
124
+ *
125
+ */
126
+void cmd_debuglog(I3_CMD, char *argument) {
127
+    LOG("%s debug logging\n", get_debug_logging() ? "Disabling" : "Enabling");
128
+    if (!strcmp(argument,"toggle"))
129
+        set_debug_logging(!get_debug_logging());
130
+    else if (!strcmp(argument, "on"))
131
+        set_debug_logging(true);
132
+    else if (!strcmp(argument, "off"))
133
+        set_debug_logging(false);
134
+    // XXX: default reply for now, make this a better reply
135
+    ysuccess(true);
136
+}

b/src/log.c

141
@@ -181,6 +181,14 @@ void set_verbosity(bool _verbose) {
142
 }
143
 
144
 /*
145
+ * Get debug logging.
146
+ *
147
+ */
148
+bool get_debug_logging() {
149
+    return debug_logging;
150
+}
151
+
152
+/*
153
  * Set debug logging.
154
  *
155
  */

b/testcases/t/187-commands-parser.t

160
@@ -144,7 +144,7 @@ is(parser_calls("\nworkspace test"),
161
 ################################################################################
162
 
163
 is(parser_calls('unknown_literal'),
164
-   "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" .
165
+   "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" .
166
    "ERROR: Your command: unknown_literal\n" .
167
    "ERROR:               ^^^^^^^^^^^^^^^",
168
    'error for unknown literal ok');