John Peacock said the following on 25/11/2005 19:44:
> Robin Bowes wrote:
> 
>>Any suggestions as to the best way to log all this information on a
>>single line so it can be easily parsed by a script for statistical purposes?
> 
> 
> When I wrote the adaptive logging feature, I wasn't concerning myself with
> parsability of the log lines because they are emitted by various and sundry
> plugins (which each log different things).  If you really want to make the 
> line
> parseable, you probably want to quote the terms (i.e. quote and comma 
> delimited).
> 
> However, that seems like an awful lot of different fields to log (for most
> people), so I'm not sure that we should include that as a default output.  How
> about cutting that out and making it a config file option.  Then it would be
> easy to eval() the contents of the config file itself to generate the log 
> line.
>  I'll know more when I see what you have already started working on...

Actually, I might as well post it now. this is jsut the hook_deny sub:

sub hook_deny {    # dlog
    my ( $self, $transaction, $prev_hook, $return, $return_text ) = @_;

    # 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') || '';

    # PID:          ${$}
    # Plugin:       $prev_hook
    # Denial Code:  $return
    # Denial Text   $return_text
    # 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;

    warn( $self->{_rejectprefix} . ' ' .
        join ",",
        ${$},
        $prev_hook,
        $return,
        $return_text,
        $sender,
        $recipients,
        $mail_size,
        $self->qp->connection->remote_host,
        $self->qp->connection->remote_ip,
        $relay_client,
        $auth_method,
        $auth_user
        . "\n"
    );

    $self->{_denied} = 1;
}

Fairly simple stuff, really.

All thoughts appreciated.

R.
-- 
http://robinbowes.com

If a man speaks in a forest,
and his wife's not there,
is he still wrong?

Reply via email to