]> gitweb.factorcode.org Git - factor.git/blobdiff - misc/fuel/fuel-log.el
Use lexical scoping in all fuel sources
[factor.git] / misc / fuel / fuel-log.el
index fee762d09a05921da0266b201ecd918db7f4bcae..bff72c1b8462ca1c878a54faee584006260b5a31 100644 (file)
@@ -1,6 +1,6 @@
-;;; fuel-log.el -- logging utilities
+;;; fuel-log.el -- logging utilities -*- lexical-binding: t -*-
 
-;; Copyright (C) 2008 Jose Antonio Ortega Ruiz
+;; Copyright (C) 2008, 2009 Jose Antonio Ortega Ruiz
 ;; See http://factorcode.org/license.txt for BSD license.
 
 ;; Author: Jose Antonio Ortega Ruiz <jao@gnu.org>
 
 (require 'fuel-base)
 
-\f
 ;;; 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
 (defvar fuel-log--inhibit-p nil
   "Set this to t to inhibit all log messages")
 
+(defvar fuel-log--debug-p nil
+  "If t, all messages are logged no matter what")
+
+;;;###autoload
 (define-derived-mode factor-messages-mode fundamental-mode "FUEL Messages"
   "Simple mode to log interactions with the factor listener"
-  (kill-all-local-variables)
   (buffer-disable-undo)
-  (set (make-local-variable 'comint-redirect-subvert-readonly) t)
+  (setq-local comint-redirect-subvert-readonly t)
   (add-hook 'after-change-functions
             '(lambda (b e len)
                (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)
-      (save-current-buffer
-        (set-buffer (get-buffer-create fuel-log--buffer-name))
+      (with-current-buffer (get-buffer-create fuel-log--buffer-name)
         (factor-messages-mode)
         (current-buffer))))
 
-(defun fuel-log--msg (type &rest args)
-  (unless fuel-log--inhibit-p
+(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)))
 
-\f
 (provide 'fuel-log)
+
 ;;; fuel-log.el ends here