logging.lisp 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. ;;; -*- Mode: Lisp; show-trailing-whitespace: t; Base: 10; indent-tabs: nil; Syntax: ANSI-Common-Lisp; Package: LOGGING; -*-
  2. ;;; Copyright (c) 2013, Mark VandenBrink. All rights reserved.
  3. (in-package #:logging)
  4. (defmacro start-logging ((name spec) &body body)
  5. `(unwind-protect
  6. (progn
  7. (log5:start-sender 'trace-log
  8. (log5:stream-sender :location ,name)
  9. :category-spec ,spec
  10. :output-spec '(log5:message log5:context))
  11. ,@body)
  12. (log5:stop-sender 'trace-log)))
  13. (defun stop-logging ()
  14. (log5:stop-sender 'trace-log))
  15. (defparameter *logging-categories* '(mp4-atom::cat-log-mp4-atom
  16. audio-streams::cat-log-stream
  17. mpeg::cat-log-mpeg-frame
  18. flac-frame::cat-log-flac-frame
  19. id3-frame::cat-log-id3-frame))
  20. (defmacro with-logging ((&optional file &key (categories *logging-categories*)) &body body)
  21. (with-gensyms (output-stream)
  22. `(let (,output-stream)
  23. (unwind-protect
  24. (setf ,output-stream (if ,file
  25. (open ,file :direction :output :if-exists :supersede :if-does-not-exist :create)
  26. *standard-output*))
  27. (log5:start-sender 'trace-log (log5:stream-sender :location ,output-stream)
  28. :category-spec ',categories
  29. :output-spec '(log5:message log5:context))
  30. ,@body)
  31. (if ,file (close ,output-stream))
  32. (log5:stop-sender 'trace-log))))