FUEL: improved logging

point goes to end of buffer and a timestamp is added
modern-harvey2
Björn Lindqvist 2017-06-30 02:27:42 +02:00
parent e27bd4020d
commit e8099389f9
1 changed files with 19 additions and 15 deletions

View File

@ -16,16 +16,15 @@
(require 'fuel-base)
;;; Customization:
(defvar fuel-log--buffer-name "*fuel messages*"
"Name of the log buffer")
(defvar fuel-log--max-buffer-size 32000
(defvar fuel-log--max-buffer-size 128000
"Maximum size of the Factor messages log")
(defvar fuel-log--max-message-size 512
(defvar fuel-log--max-message-size 1024
"Maximum size of individual log messages")
(defvar fuel-log--verbose-p t
@ -47,8 +46,7 @@
(let ((inhibit-read-only t))
(when (> b fuel-log--max-buffer-size)
(delete-region (point-min) b))))
nil t)
(setq buffer-read-only t))
nil t))
(defun fuel-log--buffer ()
(or (get-buffer fuel-log--buffer-name)
@ -56,25 +54,31 @@
(factor-messages-mode)
(current-buffer))))
(defun fuel-log--msg (type &rest args)
(defun fuel-log--timestamp ()
(format-time-string "%Y-%m-%d %T"))
(defun fuel-log--format-msg (type args)
(format "%s %s: %s\n\n" (fuel-log--timestamp) type (apply 'format args)))
(defun fuel-log--msg (type args)
(when (or fuel-log--debug-p (not fuel-log--inhibit-p))
(with-current-buffer (fuel-log--buffer)
(goto-char (point-max))
(let ((inhibit-read-only t))
(insert
(fuel-shorten-str (format "\n%s: %s\n" type (apply 'format args))
fuel-log--max-message-size))))))
(fuel-shorten-str (fuel-log--format-msg type args)
fuel-log--max-message-size))))))
(defsubst fuel-log--warn (&rest args)
(apply 'fuel-log--msg 'WARNING args))
(defun fuel-log--warn (&rest args)
(fuel-log--msg 'WARNING args))
(defsubst fuel-log--error (&rest args)
(apply 'fuel-log--msg 'ERROR args))
(defun fuel-log--error (&rest args)
(fuel-log--msg 'ERROR args))
(defsubst fuel-log--info (&rest args)
(defun fuel-log--info (&rest args)
(when fuel-log--verbose-p
(apply 'fuel-log--msg 'INFO args) ""))
(fuel-log--msg 'INFO args)))
(provide 'fuel-log)
;;; fuel-log.el ends here