Skip to content

Instantly share code, notes, and snippets.

@hyotang666
Last active October 7, 2020 20:43
Show Gist options
  • Save hyotang666/7598f4a03dde28feaec9a4e2f252410e to your computer and use it in GitHub Desktop.
Save hyotang666/7598f4a03dde28feaec9a4e2f252410e to your computer and use it in GitHub Desktop.
(defvar *logs* (make-hash-table :test #'equal))
(defmacro log! (&rest names)
(if (null names)
`(progn (maphash (lambda (name function)
(setf (fdefinition name) function))
*logs*)
(clrhash *logs*))
`(map nil (lambda (name)
(if (gethash name *logs*)
(warn "Already logging: ~S" name)
(let ((function (fdefinition name)))
(setf (gethash name *logs*) function
(fdefinition name)
(lambda (&rest args)
(format *trace-output* "~%Start: ~S" name)
(unwind-protect (apply function args)
(format *trace-output* "~%End: ~S" name)))))))
',names)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment