Opened 9 years ago

Closed 9 years ago

#702 closed enhancement (fixed)

macro expansion time category specification filter for log5scm

Reported by: Moritz Heidkamp Owned by: certainty
Priority: not urgent at all Milestone:
Component: extensions Version: 4.7.x
Keywords: log5scm Cc:
Estimated difficulty:

Description (last modified by Moritz Heidkamp)

The attached patch adds support for defining a category specification that's matched against at macro expansion time. If it matches, the log-for macro will expand to (void) and thus not generate any runtime overhead. The specification is passed through the environment variable LOG5SCM_CAT_SPEC. To implement this feature it was necessary to split the log5scm module into two modules (log5scm-lolevel and log5scm) so that the category spec matching code can be used both at macro expansion and run time.

For example, consider this program:

(use posix log5scm)

(define-category foo)
(define-category bar)

(start-sender main 
              (port-sender (current-output-port))
              (category bar))

(log-for (foo) (begin (sleep 2) "some expensive foo bar"))
(log-for (bar) "some bar")

Even though we only have a sender that's interested in log messages of the category bar the program will wait for 2 seconds because senders may change at runtime. The (sleep 2) is contrived of course, imagine building some elaborate data structure for debugging puproses there instead. Now invoking this program with LOG5SCM_CAT_SPEC=bar will completely eliminate the (log-for (foo) ...) call (well, replace it with (void) in fact). This can be useful for stripping debug messages completely from a compiled program by passing something like LOG5SCM_CAT_SPEC='(not debug)'.

Attachments (1)

syntax-category-spec-matching.patch (10.1 KB) - added by Moritz Heidkamp 9 years ago.

Download all attachments as: .zip

Change History (4)

Changed 9 years ago by Moritz Heidkamp

comment:1 Changed 9 years ago by Moritz Heidkamp

Description: modified (diff)

comment:2 Changed 9 years ago by felix winkelmann

Milestone: 4.8.0

comment:3 Changed 9 years ago by certainty

Resolution: fixed
Status: newclosed

Thanks Moritz. Your patch is very welcome and has been applied.
The new version 0.5 is available.

Note: See TracTickets for help on using tickets.