Robin Bowes said the following on 27/11/2005 14:39:
> John Peacock said the following on 27/11/2005 03:01:
>
>>Robin Bowes wrote:
>>
>>
>>>Is it possible to call the subs in the parent plugin?
>>
>>
>>That's in the example in the README.plugins:
>>
>> $self->SUPER::hook_reset_transaction( $transaction, @args );
>
>
> Ah, OK. Missed that.
>
>
>>>Would I need to do
>>>that? For example, if I override hook_reset_transaction to write a
>>>parseable accept log I would still want logging to go to the "detailed" log.
>>
>>
>>The hook_logging() actually does the detailed log; in the current plugin,
>>hook_reset_transaction() handles the accepted messages only (the hook_reject
>>is
>>just a stub). For your purposes, you can override hook_reset_transaction()
>>and
>>hook_reject() and let the base plugin handle hook_logging().
>
>
> Right, that sounds easy enough!
>
> I'll re-work my plugin and post it here when it's finished.
Hi,
I'm trying to re-work my mods to John's adaptive logging plugin to use
the isa_plugin method.
However, I'm having problems getting it to work.
Here's what I've got so far:
use warnings;
use strict;
sub init {
my ($self, $qp, %args) = @_;
$self->isa_plugin('logging/adaptive');
$self->{_acceptlevel} = LOGERROR;
if (defined($args{acceptlevel})) {
if ($args{acceptlevel} =~ /^\d+$/) {
$self->{_acceptlevel} = $args{acceptlevel};
}
else {
$self->{_acceptlevel} = log_level($args{acceptlevel});
}
}
$self->{_maxlevel} = LOGWARN;
if (defined($args{maxlevel})) {
if ($args{maxlevel} =~ /^\d+$/) {
$self->{_maxlevel} = $args{maxlevel};
}
else {
$self->{_maxlevel} = log_level($args{maxlevel});
}
}
$self->{_rejectlevel} = LOGWARN;
if (defined($args{rejectlevel})) {
if ($args{rejectlevel} =~ /^\d+$/) {
$self->{_rejectlevel} = $args{rejectlevel};
}
else {
$self->{_rejectlevel} = log_level($args{rejectlevel});
}
}
$self->{_acceptprefix} = '++';
if (defined $args{acceptprefix} and $args{acceptprefix} =~ /^(.+)$/) {
$self->{_acceptprefix} = $1;
}
$self->{_rejectprefix} = '--';
if (defined $args{rejectprefix} and $args{rejectprefix} =~ /^(.+)$/) {
$self->{_rejectprefix} = $1;
}
# 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::parseable plugin');
}
sub hook_deny {
my ($self, $transaction, $prev_hook, $return, $return_text) = @_;
my $mail_details = concat_mail_details($self, $transaction);
warn( ${$} . ' ' . $self->{_rejectprefix} . ' ' .
join ",",
$prev_hook,
$return,
$return_text,
$mail_details
. "\n"
);
$self->{_denied} = 1;
}
sub hook_reset_transaction { # slog
my ($self, $transaction, @args) = @_;
my $mail_details = concat_mail_details($self, $transaction);
warn( ${$} . ' ' .
$self->{_acceptprefix} . ' ' .
$mail_details . "\n"
);
$self->SUPER::hook_rcpt( $transaction, @args );
}
sub concat_mail_details {
my ($self, $transaction) = @_;
# mail sender (if present)
my $sender = '';
if ( defined( $transaction->sender ) ) {
$sender = $transaction->sender->format;
}
# mail recipients, if any
my $recipients = '';
if ( defined( $transaction->recipients ) ) {
my $recipients = join ';', $transaction->recipients;
}
# message size, if > 0
my $mail_size = $transaction->body_size || 0;
# relay client?
my $relay_client = (
( $transaction->{_relaying} || defined( $ENV{RELAYCLIENT} ) )
? 'yes'
: 'no'
);
# auth method, if any
my $auth_method = $self->qp->connection->notes('authmethod') || '';
# authenticated user, if any
my $auth_user = $self->qp->connection->notes('authuser') || '';
# Sender: $sender
# Recipients: $recipients
# Message size: $mail_size
# Remote Host: $self->qp->connection->remote_host
# Remote IP: $self->qp->connection->remote_ip
# Relay Client: $relay_client
# Auth method: $auth_method
# Auth user: $auth_user;
return join ",",
$sender,
$recipients,
$mail_size,
$self->qp->connection->remote_host,
$self->qp->connection->remote_ip,
$relay_client,
$auth_method,
$auth_user;
};
When I try and use this be specifying logging/parseable in
config/logging, I get the following error when a connection is made to
the SMTP port:
@4000000043b034d83ab51744 Can't locate object method "new" via package
"Qpsmtpd:
:Plugin::logging::parseable" at lib/Qpsmtpd.pm line 288.
Any idea what I'm doing wrong?
R.