PageRenderTime 129ms CodeModel.GetById 126ms app.highlight 1ms RepoModel.GetById 1ms app.codeStats 0ms

/misc/fuel/fuel-log.el

http://github.com/abeaumont/factor
Emacs Lisp | 80 lines | 48 code | 20 blank | 12 comment | 1 complexity | 4e320a51b0da55be87755793b61008e0 MD5 | raw file
 1;;; fuel-log.el -- logging utilities
 2
 3;; Copyright (C) 2008, 2009 Jose Antonio Ortega Ruiz
 4;; See http://factorcode.org/license.txt for BSD license.
 5
 6;; Author: Jose Antonio Ortega Ruiz <jao@gnu.org>
 7;; Keywords: languages, fuel, factor
 8;; Start date: Sun Dec 14, 2008 01:00
 9
10;;; Comentary:
11
12;; Some utilities for maintaining a simple log buffer, mainly for
13;; debugging purposes.
14
15;;; Code:
16
17(require 'fuel-base)
18
19
20;;; Customization:
21
22(defvar fuel-log--buffer-name "*fuel messages*"
23  "Name of the log buffer")
24
25(defvar fuel-log--max-buffer-size 32000
26  "Maximum size of the Factor messages log")
27
28(defvar fuel-log--max-message-size 512
29  "Maximum size of individual log messages")
30
31(defvar fuel-log--verbose-p t
32  "Log level for Factor messages")
33
34(defvar fuel-log--inhibit-p nil
35  "Set this to t to inhibit all log messages")
36
37(defvar fuel-log--debug-p nil
38  "If t, all messages are logged no matter what")
39
40(define-derived-mode factor-messages-mode fundamental-mode "FUEL Messages"
41  "Simple mode to log interactions with the factor listener"
42  (kill-all-local-variables)
43  (buffer-disable-undo)
44  (set (make-local-variable 'comint-redirect-subvert-readonly) t)
45  (add-hook 'after-change-functions
46            '(lambda (b e len)
47               (let ((inhibit-read-only t))
48                 (when (> b fuel-log--max-buffer-size)
49                   (delete-region (point-min) b))))
50            nil t)
51  (setq buffer-read-only t))
52
53(defun fuel-log--buffer ()
54  (or (get-buffer fuel-log--buffer-name)
55      (save-current-buffer
56        (set-buffer (get-buffer-create fuel-log--buffer-name))
57        (factor-messages-mode)
58        (current-buffer))))
59
60(defun fuel-log--msg (type &rest args)
61  (when (or fuel-log--debug-p (not fuel-log--inhibit-p))
62    (with-current-buffer (fuel-log--buffer)
63      (let ((inhibit-read-only t))
64        (insert
65         (fuel--shorten-str (format "\n%s: %s\n" type (apply 'format args))
66                            fuel-log--max-message-size))))))
67
68(defsubst fuel-log--warn (&rest args)
69  (apply 'fuel-log--msg 'WARNING args))
70
71(defsubst fuel-log--error (&rest args)
72  (apply 'fuel-log--msg 'ERROR args))
73
74(defsubst fuel-log--info (&rest args)
75  (when fuel-log--verbose-p
76    (apply 'fuel-log--msg 'INFO args) ""))
77
78
79(provide 'fuel-log)
80;;; fuel-log.el ends here