Re: Logs, hooks, and sublogs

From: Bjarni R. Einarsson (
Date: Thu 20 Sep 2001 - 11:48:11 UTC

  • Next message: Bjarni R. Einarsson: "CODE: Common message data exposed."

    Your analysis of the log/sublog code is accurate...

    On 2001-09-19, 14:32:40 (-0500), Sterling Hanenkamp wrote:
    > My question is, how are hooks added to sublogs? Is it intended that the
    > user write a hook that is set to be called on various known sublog creation
    > events (e.g., "ScanFile", "SanitizeFile", "Match", etc.) and in that hook
    > the user adds hooks to the sublog? Or is there another mechanism that
    > should be added here?

    This is one thing I hadn't quite finished. My last thought on the
    matter was, as you guessed, that hook users would simply add hooks
    which register more hooks within sublgs. This is the most flexible
    method (it allows a tag to mean different things within different
    sublogs), although it has the drawback that it requires alot of
    "bookkeeping" code, which is always a pain to write.

    So yes, something easier to use should probably be added...

    Would it make sense to provide both global and local hooks? The
    local hooks would behave just like the current implementation, but
    global hooks are inherited by a sublog from it's parent?

    I've implemented this within my here, just to try it out. The
    interface is exactly the same as before, but now if you add a third
    non-zero parameter to the add_hook call it will register a global hook
    instead of a local one:

     $log->add_hook("thing", sub { print "Ooh, a new thing!\n"; }, "global" );

    All global hooks are inherited when sublogs are attached to a parent

    The code passes my regression test and unless someone suggests
    something even better I'll include it in the next Sanitizer release.
    In the meantime, you can grab a copy here:

    My implementation has the caveat that when attaching log A to log B
    via. the sublog method, A's global hooks will be overwritten by B's.
    I don't think this is a problem, but it's something to keep in mind.

    I'm curios - the code you're writing, are you writing it as a
    replacement for the script, or a seperate module which
    can be included in such scripts? May I see your code? :-)

    Bjarni R. Einarsson                           PGP: 02764305, B7A3AB89                -><-    

    Check out my open-source email sanitizer:

    hosted by