(require 'cl-lib) (defvar structlog-fields nil "Currently selected structlog fields") (defvar structlog-logs nil "Current structlog log lines, formatted as plists") (defun structlog--make-list-entries () "Makes the tabulated-list-mode entries list for structlog" (cl-map 'list (lambda (log-plist) (list log-plist (cl-map 'vector (lambda (field) (plist-get log-plist field)) structlog-fields))) structlog-logs)) (define-derived-mode structlog-mode tabulated-list-mode "structlog" "Major mode to query structured log lines" (setq tabulated-list-format (cl-map 'vector (lambda (field) (list (symbol-name field) 20 t)) structlog-fields) tabulated-list-entries #'structlog--make-list-entries) (tabulated-list-init-header)) ;;;###autoload (defun structlog () (interactive) (when (get-buffer "*structlog*") (kill-buffer "*structlog*")) (with-current-buffer (get-buffer-create "*structlog*") ;; TODO do something real here (setq structlog-fields '(time event) structlog-logs '((time "2020-06-02T16:55:00" event "Got a baz") (time "2020-06-02T17:00:00" event "Got a bar") (time "2020-06-02T17:04:00" event "Got a foo"))) (structlog-mode) (tabulated-list-print)) (switch-to-buffer "*structlog*"))