about summary refs log tree commit diff
diff options
context:
space:
mode:
authorChris Feng <chris.w.feng@gmail.com>2019-09-08T00·00+0000
committerChris Feng <chris.w.feng@gmail.com>2019-09-08T00·00+0000
commit2d36241a10b4b705e1482322383f135bca7ac184 (patch)
tree4c1d0edbb2320cea4f4cbbb755e19ef98aad3a35
parentf303517c297a9ca9e6a814897f96303b5d0f02be (diff)
Add timestamps to `exwm-debug' logs
* exwm-core.el (exwm-debug-log-time-function): New user option for
choosing the style of timestamps in debug logs.
(exwm-debug-log-uptime, exwm-debug-log-time): Possible candidates for
it.
(exwm--log): Use it.
-rw-r--r--exwm-core.el26
1 files changed, 25 insertions, 1 deletions
diff --git a/exwm-core.el b/exwm-core.el
index d3edb146ec99..ed9a523448bc 100644
--- a/exwm-core.el
+++ b/exwm-core.el
@@ -33,6 +33,27 @@
 (require 'xcb-ewmh)
 (require 'xcb-debug)
 
+(defcustom exwm-debug-log-time-function #'exwm-debug-log-uptime
+  "Function used for generating timestamps in `exwm-debug' logs.
+
+Here are some predefined candidates:
+`exwm-debug-log-uptime': Display the uptime of this Emacs instance.
+`exwm-debug-log-time': Display time of day.
+`nil': Disable timestamp."
+  :group 'exwm
+  :type `(choice (const :tag "Emacs uptime" ,#'exwm-debug-log-uptime)
+                 (const :tag "Time of day" ,#'exwm-debug-log-time)
+                 (const :tag "Off" nil)
+                 (function :tag "Other")))
+
+(defun exwm-debug-log-uptime ()
+  "Add uptime to `exwm-debug' logs."
+  (emacs-uptime "[%.2h:%.2m:%.2s] "))
+
+(defun exwm-debug-log-time ()
+  "Add time of day to `exwm-debug' logs."
+  (format-time-string "[%T] "))
+
 (defvar exwm--connection nil "X connection.")
 
 (defvar exwm--wmsn-window nil
@@ -79,7 +100,10 @@ FORMAT-STRING is a string specifying the message to output, as in
 `format'.  The OBJECTS arguments specify the substitutions."
   (unless format-string (setq format-string ""))
   `(when exwm-debug
-     (xcb-debug:message ,(concat "%s:\t" format-string "\n")
+     (xcb-debug:message ,(concat "%s%s:\t" format-string "\n")
+                        (if exwm-debug-log-time-function
+                            (funcall exwm-debug-log-time-function)
+                          "")
                         (xcb-debug:compile-time-function-name)
                         ,@objects)
      nil))