#!/usr/bin/perl # this is a simple 'warn' plugin like the default builtin logging # # It demonstrates that a logging plugin can call ->log itself as well # as how to ignore log entries from itself sub register { my ($self, $qp, $loglevel) = @_; $self->{_level} = LOGWARN; if (defined($loglevel) and ($loglevel =~ /^\d+$/)) { $self->{_level} = $loglevel; } $self->register_hook('logging', 'wlog'); # If you want to capture this log entry with this plugin, you need to # wait until after you register the plugin $self->log(LOGINFO,'Initializing logging::warn plugin'); } sub wlog { my ($self, $transaction, $trace, $hook, $plugin, @log) = @_; # Don't log your own log entries! If this is the only logging plugin # then these lines will not be logged at all. You can safely comment # out this line and it will not cause an infinite loop. return DECLINED if defined $plugin and $plugin eq $self->plugin_name; warn join(" ", $$ . (defined $plugin ? " $plugin plugin:" : defined $hook ? " running plugin ($hook):" : ""), @log), "\n" if ($trace <= $self->{_level}); return DECLINED; }