From 1f40ef408641680c951a65b72be240d9b7729d8e Mon Sep 17 00:00:00 2001 From: Craig Jennings Date: Sat, 8 Nov 2025 11:53:02 -0600 Subject: feat: debug: add comprehensive debug logging and integration tests MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Enhanced wttrin-debug.el: - Added wttrin--debug-log() function for timestamped logging - Added wttrin--debug-clear-log() to clear log - Added wttrin--debug-show-log() to display log in buffer - Debug log structure: list of (timestamp . message) pairs Added debug logging to key functions in wttrin.el: - wttrin--fetch-url: Logs start, success (bytes), and errors - wttrin--mode-line-fetch-weather: Logs start, URL, data received - wttrin--mode-line-update-display: Logs display update, emoji extraction Created comprehensive integration tests: - test-wttrin-integration-with-debug.el (5 tests, 3 passing) - Tests fetch, mode-line display, error handling with debug logging - Includes mocked network calls to avoid external dependencies - Example debug output shows complete flow: [wttrin-debug 11:51:46.490] mode-line-fetch: Starting fetch for Berkeley, CA [wttrin-debug 11:51:46.490] mode-line-fetch: Received data = "Berkeley, CA: ☀️ +62°F Clear" [wttrin-debug 11:51:46.490] mode-line-display: Extracted emoji = "☀", font = Noto Color Emoji [wttrin-debug 11:51:46.490] mode-line-display: Complete. mode-line-string set = YES Added test fixtures: - tests/fixtures/test-init.el: Minimal config with debug enabled - tests/README-DEBUG-TESTS.md: Documentation for using debug features Usage: (setq wttrin-debug t) ; Before loading wttrin (require 'wttrin) M-x wttrin--debug-show-log ; View all logged events This provides complete visibility into wttrin's operation for troubleshooting. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- wttrin-debug.el | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) (limited to 'wttrin-debug.el') diff --git a/wttrin-debug.el b/wttrin-debug.el index 55546d4..0ddecab 100644 --- a/wttrin-debug.el +++ b/wttrin-debug.el @@ -103,5 +103,38 @@ This function is called automatically when wttrin runs if debug mode is enabled. It creates the *wttrin-mode-debug* buffer with diagnostic information." (debug-wttrin-mode-line)) +(defvar wttrin--debug-log nil + "List of debug log entries. Each entry is (timestamp . message).") + +(defun wttrin--debug-log (format-string &rest args) + "Log a debug message if wttrin-debug is enabled. +FORMAT-STRING and ARGS are passed to `format'." + (when wttrin-debug + (let ((msg (apply #'format format-string args)) + (timestamp (format-time-string "%H:%M:%S.%3N"))) + (push (cons timestamp msg) wttrin--debug-log) + (message "[wttrin-debug %s] %s" timestamp msg)))) + +(defun wttrin--debug-clear-log () + "Clear the debug log." + (interactive) + (setq wttrin--debug-log nil) + (message "Wttrin debug log cleared")) + +;;;###autoload +(defun wttrin--debug-show-log () + "Display the wttrin debug log in a buffer." + (interactive) + (with-current-buffer (get-buffer-create "*wttrin-debug-log*") + (erase-buffer) + (insert "=== WTTRIN DEBUG LOG ===\n") + (insert (format "Total entries: %d\n\n" (length wttrin--debug-log))) + (if wttrin--debug-log + (dolist (entry (reverse wttrin--debug-log)) + (insert (format "[%s] %s\n" (car entry) (cdr entry)))) + (insert "(No log entries yet)\n")) + (goto-char (point-min)) + (display-buffer (current-buffer)))) + (provide 'wttrin-debug) ;;; wttrin-debug.el ends here -- cgit v1.2.3