7max/log4cl

Add syntax sugar for logging macros to drop innermost level of auto-naming

7max opened this issue · 0 comments

7max commented

There is an often used pattern is Lisp for writing wrappers like this:

(defun call-with-wrapping (thunk)
  (unwind-protect 
      (progn
         (log:trace "Wrapping is on")
         (funcall thunk))
    (log:trace "Wrapping is off")

(defmacro with-wrapping (&body body)
  `(call-with-wrapping (lambda () ,@body))

(defun foobar ()
  (call-with-wrapping ...))

Currently above results in log category auto-naming making the log category
of package.foobar.call-with-wrapping.lambda, which is too much information we don't want.

Its possible to fix the above pattern, by adding a logger object argument to call-with-wrapping, and passing the logger object to macro like this.

(defun call-with-wrapping (logger thunk)
  (unwind-protect 
      (progn
         (log:trace :logger logger "Wrapping is on")
         (funcall thunk))
    (log:trace :logger logger  "Wrapping is off")

(defmacro with-wrapping (&body body)
  `(call-with-wrapping (log:category) (lambda () ,@body))

(defun foobar ()
  (call-with-wrapping ...))

But it would be nice if above can be done without such workaround, by adding some syntax sugar to logging macros, that indicate that auto category naming should drop a level, something like (log:trace /// ....) or (log:trace ***) to indicate that naming should drop 3 levels