Logs, hooks, and sublogs

From: Sterling Hanenkamp (
Date: Wed 19 Sep 2001 - 19:32:40 UTC

  • Next message: Sterling Hanenkamp: "Re: Custom issues"

    I want to make sure I understand both how the code works and the intentions of the code when it comes to sublogs and hooks, for future use. In the sublog method we have this code:

    sub sublog
        my ($self, $tag, $level, $attr, $sl) = @_;
        $sl = new Anomy::Log unless ($sl);

        $level = 0 unless ($level);
        $level |= SLOG_SUBLOG;

        my $entry = [ LOG_SUBLOG, $tag, $level, $attr || { }, $sl ];
        push @{ $self->{"log"} }, $entry if ($self->check_hook($entry));
        return $sl;

    First, we create a new Log named $sl unless the user has already created a log object we are to use. Next, we create the sublog log entry, which will be used to attach the sublog to the parent log. Finally, we run all hooks associated with the tag (given in the new $entry hash reference). If any hook returns false, then the sublog is not appended to the log and it is effectively removed from eventual output while still maintaining an object so the user doesn't have to program for an undef contingency. Otherwise, the sublog is pushed onto the log and may eventually be used as part of output to stderr, inline, etc. That's how it works.

    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?


    <>< ><> <>< ><> <>< ><> <>< ><> <>< ><> <>< ><>
     Sterling Hanenkamp
     Software Consultant
     Network Resource Group, Inc.
     1105 Hylton Heights
     Manhattan, KS  66502
     (785) 776-5878

    hosted by