logging.lisp 1.2 KB

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