logging.lisp 1.5 KB

12345678910111213141516171819202122232425262728293031323334
  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. (defparameter *logging-categories* '(mp4-atom::cat-log-mp4-atom
  14. audio-streams::cat-log-stream
  15. mpeg::cat-log-mpeg-frame
  16. flac-frame::cat-log-flac-frame
  17. id3-frame::cat-log-id3-frame))
  18. (defmacro with-logging ((&optional file &key (categories *logging-categories*)) &body body)
  19. (with-gensyms (output-stream)
  20. `(let (,output-stream)
  21. (unwind-protect
  22. (setf ,output-stream (if ,file
  23. (open ,file :direction :output :if-exists :supersede :if-does-not-exist :create)
  24. *standard-output*))
  25. (log5:start-sender 'trace-log (log5:stream-sender :location ,output-stream)
  26. :category-spec ',categories
  27. :output-spec '(log5:message log5:context))
  28. ,@body)
  29. (if ,file (close ,output-stream))
  30. (log5:stop-sender 'trace-log))))