1 ;;; fuel-log.el -- logging utilities
3 ;; Copyright (C) 2008 Jose Antonio Ortega Ruiz
4 ;; See http://factorcode.org/license.txt for BSD license.
6 ;; Author: Jose Antonio Ortega Ruiz <jao@gnu.org>
7 ;; Keywords: languages, fuel, factor
8 ;; Start date: Sun Dec 14, 2008 01:00
12 ;; Some utilities for maintaining a simple log buffer, mainly for
13 ;; debugging purposes.
22 (defvar fuel-log--buffer-name
"*fuel messages*"
23 "Name of the log buffer")
25 (defvar fuel-log--max-buffer-size
32000
26 "Maximum size of the Factor messages log")
28 (defvar fuel-log--max-message-size
512
29 "Maximum size of individual log messages")
31 (defvar fuel-log--verbose-p t
32 "Log level for Factor messages")
34 (defvar fuel-log--inhibit-p nil
35 "Set this to t to inhibit all log messages")
37 (define-derived-mode factor-messages-mode fundamental-mode
"FUEL Messages"
38 "Simple mode to log interactions with the factor listener"
39 (kill-all-local-variables)
41 (set (make-local-variable 'comint-redirect-subvert-readonly
) t
)
42 (add-hook 'after-change-functions
44 (let ((inhibit-read-only t
))
45 (when (> b fuel-log--max-buffer-size
)
46 (delete-region (point-min) b
))))
48 (setq buffer-read-only t
))
50 (defun fuel-log--buffer ()
51 (or (get-buffer fuel-log--buffer-name
)
53 (set-buffer (get-buffer-create fuel-log--buffer-name
))
54 (factor-messages-mode)
57 (defun fuel-log--msg (type &rest args
)
58 (unless fuel-log--inhibit-p
59 (with-current-buffer (fuel-log--buffer)
60 (let ((inhibit-read-only t
))
62 (fuel--shorten-str (format "\n%s: %s\n" type
(apply 'format args
))
63 fuel-log--max-message-size
))))))
65 (defsubst fuel-log--warn
(&rest args
)
66 (apply 'fuel-log--msg
'WARNING args
))
68 (defsubst fuel-log--error
(&rest args
)
69 (apply 'fuel-log--msg
'ERROR args
))
71 (defsubst fuel-log--info
(&rest args
)
72 (when fuel-log--verbose-p
73 (apply 'fuel-log--msg
'INFO args
) ""))
77 ;;; fuel-log.el ends here