logging.lisp 1.3 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. mp4-file::cat-log-mp4-file
  15. base-file::cat-log-base-file
  16. mp3-frame::cat-log-mp3-frame
  17. mp3-file::cat-log-mp3-file))
  18. (defmacro with-logging ((&key (file nil) (categories *logging-categories*)) &body body)
  19. (alexandria:with-gensyms (output-stream)
  20. `(let (,output-stream)
  21. (unwind-protect
  22. (setf ,output-stream (if ,file
  23. (open ,file :direction :output :if-exists :overwrite :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))))