(defun dojo-common-log-clear-user-log () (let* ((output-buffer "*Info*")) (save-current-buffer (set-buffer (get-buffer-create output-buffer)) (erase-buffer) (let ((windows-for-buffer (get-buffer-window-list output-buffer))) (dolist (window windows-for-buffer) (set-window-point window (point-max))))))) (defun dojo-common-log-split-and-show-user-log-buffer () (interactive) (delete-other-windows) (split-window-below) (other-window 1) (switch-to-buffer "*Info*") (dojo-common-log-clear-user-log) (other-window 1)) (defun dojo-common-log-limit-buffer-size (buffer-name) "Limits the size of the given buffer. If it exceeds dojo-log-buffer-limit, the first half of the buffer will be cut at a line end and discarded." (let* ((buffer (get-buffer buffer-name)) (size (if buffer (buffer-size buffer) nil))) (if (and size (> size dojo-log-buffer-limit)) (progn (with-current-buffer buffer (buffer-disable-undo (current-buffer)) ; Effective longer than this function run, should basically be active always for log buffers (goto-char (- size (/ dojo-log-buffer-limit 2))) (beginning-of-line) (delete-region (point-min) (point)) (goto-char (point-max))) (log-workloop (format "... Cut log buffer [%s] since it grew too large (%s > %s)" buffer-name size dojo-log-buffer-limit)))))) ; (log-user (format "[LOG] Cut log buffer [%s] since it grew too large (%s > %s)" buffer-name size dojo-log-buffer-limit)) (defun dojo-common-log-limit-all-log-buffers () (log-workloop (format "[LIMIT-BUFFER-SIZE] Limiting buffer sizes...")) (dojo-common-log-limit-buffer-size "*User Log*") (dojo-common-log-limit-buffer-size "*Workspace Inspection Log*") (dojo-common-log-limit-buffer-size "*Workspace Detail Log*") (dojo-common-log-limit-buffer-size "*Workloop Log*") (dojo-common-log-limit-buffer-size "*Extract Js Log*") (dojo-common-log-limit-buffer-size "*Log*") (dojo-common-log-limit-buffer-size "*Summary Log*") (dojo-common-log-limit-buffer-size "*Prio Log*") (dojo-common-log-limit-buffer-size "*Extract Assignments Log*") (dojo-common-log-limit-buffer-size "*Completion Generation Log*") (dojo-common-log-limit-buffer-size "*Dependency Log*") (dojo-common-log-limit-buffer-size "*Inspect Log*") (dojo-common-log-limit-buffer-size "*Data Log*") (dojo-common-log-limit-buffer-size "*Job Control Log*") (dojo-common-log-limit-buffer-size "*Indendation Log*") (dojo-common-log-limit-buffer-size "*Js API Log*") (dojo-common-log-limit-buffer-size "*Key Log*") (dojo-common-log-limit-buffer-size "*Save Log*") (dojo-common-log-limit-buffer-size "*Load Log*") (dojo-common-log-limit-buffer-size "*Trace Log*") (dojo-common-log-limit-buffer-size "*I18n Log*") (dojo-common-log-limit-buffer-size "*Java Log*") (dojo-common-log-limit-buffer-size "*CSS Log*") (dojo-common-log-limit-buffer-size "*js2 Log*") (dojo-common-log-limit-buffer-size "*Code Generation Log*") (dojo-common-log-limit-buffer-size "*Blueprint Parse Log*") (dojo-common-log-limit-buffer-size "*Window Log*") (log-workloop (format "... Done."))) (defun log-user (msg) (progn (do-log "*User Log*" msg))) (defun do-log (output-buffer msg) (if dojo-activate-log (save-current-buffer (set-buffer (get-buffer-create output-buffer)) (insert (concat (format-time-string "%Y-%m-%d %H:%M:%S,%3N | ") msg)) (newline) (let ((windows-for-buffer (get-buffer-window-list output-buffer)) ) (dolist (window windows-for-buffer) (set-window-point window (point-max)) ) ) ) ) ) (defun dojo-common-log-get-memory-info () "Returns a summary string containing (hopefully) interesting information about memory usage. Meant to be used in debug code. Based on the output of (garbage-collect)." (if dojo-enable-memory-log (let* ((garbage-collect-output (garbage-collect)) (conses (nth 0 garbage-collect-output)) (symbols (nth 1 garbage-collect-output)) (string-bytes (nth 4 garbage-collect-output)) (cons-size (nth 1 conses)) (used-conses (nth 2 conses)) (symbol-size (nth 1 symbols)) (used-symbols (nth 2 symbols)) (used-bytes (nth 2 string-bytes))) ; (format "[Conses %s, symbols %s, strings %s]" (* cons-size used-conses) (* symbol-size used-symbols) used-bytes))) (format "[Symbols %s, strings %s, memory-limit %s]" (* symbol-size used-symbols) used-bytes (memory-limit))) (format "[memory info deactivated]"))) (defun dojo-common-log-log-memory-info () (interactive) (log-workspace ( format " Current memory usage ............................. MEMORY: %s" (dojo-common-log-get-memory-info)))) (defun log-workspace (msg) (if dojo-activate-workspace-log (progn (do-log "*Workspace Inspection Log*" msg))) (log-workspace-details msg)) (defun log-workspace-details (msg) (if dojo-activate-workspace-log (do-log "*Workspace Detail Log*" msg))) (defun log-workloop (msg) (if dojo-activate-workspace-log (progn (do-log "*Workloop Log*" msg) (log-workspace msg)))) (defun log-extract (msg) (if (or nil (null dojo-process-workspace-timer)) (progn (do-log "*Extract Js Log*" msg) (log-assign 0 msg) (do-log "*Log*" msg)))) (defun log-extract-summary (level msg) (let* ((prefix "")) (dotimes (n (* 2 level)) (setq prefix (concat prefix " "))) (do-log "*Summary Log*" (concat prefix msg)))) ; (log-assign level msg) ; (do-log "*Log*" (concat prefix msg)))) (defun log-extract-prio (msg) (do-log "*Prio Log*" msg)) (defun log-assign (level msg) ; (if (null dojo-process-workspace-timer) (let* ((prefix "")) (dotimes (n (* 2 level)) (setq prefix (concat prefix " "))) (do-log "*Extract Assignments Log*" (concat prefix msg)))) (defun log-completion (level msg) (let* ((prefix "") ) (dotimes (n (* 2 level)) (setq prefix (concat prefix " ")) ) (do-log "*Completion Generation Log*" (concat prefix msg)) (do-log "*Log*" (concat prefix msg)) ) ) (defun log-dep (msg) (do-log "*Dependency Log*" msg)) (defun log-inspect (msg) (do-log "*Inspect Log*" msg)) (defun log-data (msg) (if (null dojo-process-workspace-timer) (let ((full-msg (concat "[DATA] " msg))) (do-log "*Data Log*" full-msg)))) (defun log-job (msg) (do-log "*Job Control Log*" msg)) (defun log-indent (msg) (if dojo-activate-indent-log (progn (do-log "*Indendation Log*" msg)))) (defun log-js-api (msg) (do-log "*Js API Log*" msg)) (defun log-key (msg) (do-log "*Key Log*" msg)) (defun log-save (msg) (do-log "*Save Log*" msg)) (defun log-load (msg) (do-log "*Load Log*" msg)) (defun log-tree (msg) (do-log "*Tree Log*" msg)) (defun log-trace (msg) (do-log "*Trace Log*" msg)) (defun log-i18n (msg) (do-log "*I18n Log*" msg)) (defun log-java (msg) (do-log "*Java Log*" msg)) (defun log-css (msg) (do-log "*CSS Log*" msg)) (defun log-js2 (msg) (do-log "*js2 Log*" msg)) (defun log-codegen (msg) (do-log "*Code Generation Log*" msg)) (defun log-blueprint-completion (msg) (do-log "*Blueprint Completion Log*" msg)) (defun log-blueprint-parse (msg) (do-log "*Blueprint Parse Log*" msg)) (defun log-window (msg) (do-log "*Window Log*" msg)) (provide 'dojo-common-log)