logger.lisp 794 Bytes
Newer Older
Francois-Rene Rideau's avatar
Francois-Rene Rideau committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
;;; -*- Mode: Lisp ; Base: 10 ; Syntax: ANSI-Common-Lisp -*-
;;;;; Trivial Logging mechanism

(in-package :philip-jose)

(defun trivial-logger (s fmt &rest args)
  (with-standard-io-syntax
    (let ((s (or s *error-output*))
          (*print-pretty* nil)
          (*print-readably* nil))
      (format s "~&")
      (apply #'format s fmt args)
      (format s "~&")
      (finish-output s))))

(def*fun logger (fmt &rest args)
  (apply #'trivial-logger *error-output* fmt args))

(def*macro with-trivial-logging ((&optional s) &body body)
  `(let ((*error-output* (or ,s *error-output*)))
    (handler-bind
        ((condition #'(lambda (condition)
                        (logger "~&~S~%" condition)
                        #+sbcl (ignore-errors (sb-debug:backtrace 100)))))
      ,@body)))