Matt Sergeant wrote:
On 14 Mar 2005, at 17:22, Ask Bjørn Hansen wrote:

I don't think I like putting so much meaning into the number of parameters (or maybe I misunderstood you).


Me either. The current interpretation would just log everything you send in @_ (i.e. like warn() and print() do).

I'm sorry, I should have made clear that from the caller's perspective, nothing changes, so we don't have to change any call to $self->log(). See the attached patch for an example implementation (which nicely indents the related log entries as a side effect).


I could use a hash instead, but it really doesn't aid in clarity much, since only the logging plugin itself cares, and we can simply document the parameters that are passed. And a hash is going to always be slower, not that we don't pay that cost quite a lot already.

John
=== lib/Qpsmtpd/Plugin.pm
==================================================================
--- lib/Qpsmtpd/Plugin.pm  (revision 411)
+++ lib/Qpsmtpd/Plugin.pm  (local)
@@ -41,7 +41,7 @@
 
 sub log {
   my $self = shift;
-  $self->qp->log(shift, $self->plugin_name . " plugin: " . shift, @_);
+  $self->qp->log(shift, undef, $self->plugin_name, @_);
 }
 
 sub transaction {
=== lib/Qpsmtpd.pm
==================================================================
--- lib/Qpsmtpd.pm  (revision 411)
+++ lib/Qpsmtpd.pm  (local)
@@ -27,10 +27,24 @@
 }
 
 sub log {
-  my ($self, $trace, @log) = @_;
+  my ($self, $trace) = (shift,shift);
+  my ($hook, $plugin, @log);
+  if ( $#_ == 0 ) { # log itself
+    (@log) = @_;
+  }
+  elsif ( $#_ == 1 ) { # plus the hook
+    ($hook, @log) = @_;
+  }
+  else { # called from plugin
+    ($hook, $plugin, @log) = @_;
+  }
+
   my $level = TRACE_LEVEL();
   $level = $self->init_logger unless defined $level;
-  warn join(" ", $$, @log), "\n"
+  warn join(" ", $$, 
+      defined $hook ? "running plugin ($hook):" : "",
+      defined $plugin ? "$plugin plugin:" : "",
+      @log), "\n"
     if $trace <= $level;
 }
 
@@ -206,7 +220,7 @@
   if ($hooks->{$hook}) {
     my @r;
     for my $code (@{$hooks->{$hook}}) {
-      $self->log(LOGINFO, "running plugin ($hook):", $code->{name});
+      $self->log(LOGINFO, $hook, $code->{name});
       eval { (@r) = $code->{code}->($self, $self->transaction, @_); };
       $@ and $self->log(LOGCRIT, "FATAL PLUGIN ERROR: ", $@) and next;
 

Reply via email to