logging.lisp 1.5 KB

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