refactor(lib): tidy doom-log output
This commit reduces the debug log noise, makes it easier to read/parse/search, and soft-introduces a convention for doom-log messages, where they are prefixed with a unique identifier loosely named after it's running context or calling function. I haven't enforced it everywhere doom-log is used yet, but this is a start.
This commit is contained in:
parent
0c43c769ef
commit
6cac7b05b6
8 changed files with 68 additions and 66 deletions
|
@ -28,36 +28,37 @@
|
|||
Each entry can be a variable symbol or a cons cell whose CAR is the variable
|
||||
symbol and CDR is the value to set it to when `doom-debug-mode' is activated.")
|
||||
|
||||
(defvar doom-debug--undefined-vars nil)
|
||||
(defvar doom-debug--unbound-vars nil)
|
||||
|
||||
(defun doom-debug--watch-vars-h (&rest _)
|
||||
(when-let (bound-vars (cl-delete-if-not #'boundp doom-debug--undefined-vars))
|
||||
(doom-log "New variables available: %s" bound-vars)
|
||||
(let ((message-log-max nil))
|
||||
(doom-debug-mode -1)
|
||||
(doom-debug-mode +1))))
|
||||
(when-let (vars (copy-sequence doom-debug--unbound-vars))
|
||||
(setq doom-debug--unbound-vars nil)
|
||||
(mapc #'doom-debug--set-var vars)))
|
||||
|
||||
(defun doom-debug--set-var (spec)
|
||||
(cond ((listp spec)
|
||||
(pcase-let ((`(,var . ,val) spec))
|
||||
(if (boundp var)
|
||||
(set-default
|
||||
var (if (not doom-debug-mode)
|
||||
(prog1 (get var 'initial-value)
|
||||
(put var 'initial-value nil))
|
||||
(doom-log "debug:vars: %s = %S" var (default-toplevel-value var))
|
||||
(put var 'initial-value (default-toplevel-value var))
|
||||
val))
|
||||
(add-to-list 'doom-debug--unbound-vars spec))))
|
||||
((boundp spec)
|
||||
(doom-log "debug:vars: %s = %S" spec doom-debug-mode)
|
||||
(set-default-toplevel-value spec doom-debug-mode))
|
||||
((add-to-list 'doom-debug--unbound-vars (cons spec t)))))
|
||||
|
||||
;;;###autoload
|
||||
(define-minor-mode doom-debug-mode
|
||||
"Toggle `debug-on-error' and `init-file-debug' for verbose logging."
|
||||
:init-value init-file-debug
|
||||
:global t
|
||||
(let ((enabled doom-debug-mode))
|
||||
(setq doom-debug--undefined-vars nil)
|
||||
(dolist (var doom-debug-variables)
|
||||
(cond ((listp var)
|
||||
(pcase-let ((`(,var . ,val) var))
|
||||
(if (boundp var)
|
||||
(set-default
|
||||
var (if (not enabled)
|
||||
(prog1 (get var 'initial-value)
|
||||
(put var 'initial-value nil))
|
||||
(put var 'initial-value (default-toplevel-value var))
|
||||
val))
|
||||
(add-to-list 'doom-debug--undefined-vars var))))
|
||||
((if (boundp var)
|
||||
(set-default-toplevel-value var enabled)
|
||||
(add-to-list 'doom-debug--undefined-vars var)))))
|
||||
(doom-log "debug: enabled!")
|
||||
(mapc #'doom-debug--set-var doom-debug-variables)
|
||||
(when (called-interactively-p 'any)
|
||||
(when (fboundp 'explain-pause-mode)
|
||||
(explain-pause-mode (if enabled +1 -1))))
|
||||
|
@ -65,7 +66,8 @@ symbol and CDR is the value to set it to when `doom-debug-mode' is activated.")
|
|||
;; potentially define one of `doom-debug-variables'), in case some of them
|
||||
;; aren't defined when `doom-debug-mode' is first loaded.
|
||||
(cond (enabled
|
||||
(message "Debug mode enabled! (Run 'M-x view-echo-area-messages' to open the log buffer)")
|
||||
(unless noninteractive
|
||||
(message "Debug mode enabled! (Run 'M-x view-echo-area-messages' to open the log buffer)"))
|
||||
;; Produce more helpful (and visible) error messages from errors
|
||||
;; emitted from hooks (particularly mode hooks), that usually go
|
||||
;; unnoticed otherwise.
|
||||
|
@ -83,6 +85,7 @@ symbol and CDR is the value to set it to when `doom-debug-mode' is activated.")
|
|||
(advice-remove #'gcmh-idle-garbage-collect #'doom-debug-shut-up-a)
|
||||
(remove-variable-watcher 'doom-debug-variables #'doom-debug--watch-vars-h)
|
||||
(remove-hook 'after-load-functions #'doom-debug--watch-vars-h)
|
||||
(doom-log "debug: disabled")
|
||||
(message "Debug mode disabled!")))))
|
||||
|
||||
(defun doom-debug-shut-up-a (fn &rest args)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue