Ask Bjørn Hansen said the following on 02/19/2006 06:53 PM:
>
> On Feb 18, 2006, at 6:30 PM, Robin Bowes wrote:
>
> [...]
>
>> 1. Use some separator character other than comma that can be guaranteed
>> not to occur in any of the list items
>>
>> 2. Quote each item, if necessary.
>
> [...]
>
>>
>> Is it OK to add a dependency on Text::CSV_XS ?
>
>
> I dislike tab delimited output as much as the next guy, but maybe it'd
> be appropriate here?
Yes, I'm not a fan but I agree it does seem to make sense here.
My main considerations for this are:
1. Easy to parse final log file
2. lightweight process to create log file
3. minimal dependencies
So, thinking through how this would work...
I could create the log line using:
warn( ${$} . ' ' . $self->{_rejectprefix} . ' ' .
join "\t",
$prev_hook,
$return,
#
# rest of fields
#
. "\n"
);
The log line (in the file, i.e. with the timestamp) would look something
like:
@4000000043f8bb5d11a69bac 9989 -- spamassassin\t901\tspam score exceeded
threshold (#5.6.1)\t\t\t<[EMAIL PROTECTED]>\t\t5002\t
mur78-1-82-232-29-188.fbx.proxad.net,82.232.29.188\tno\t\t
This could be processed using something like:
while (<>)
chomp;
# logfile is in format "timestamp pid -- <rest of line>"
if (/(@[[:xdigit:]]{24}) ([[:digit:]]+) -- (.*)/) {
my ($timestamp, $pid, $restofline) = ($1, $2, $3);
my @fields = split "\t", $restofline;
# do stuff with @fields
}
}
The only possible problem would be if any of the fields could possibly
contain a tab character.
I'm currently using the following fields:
# PID: ${$}
# Plugin: $prev_hook
# Denial Code: $return
# Denial Text $return_text
# Message-Id: $msgid
# 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;
Of these, I believe only $sender and $recipients are likely to contain
the tab character. So, I could s/\t//g these two strings.
How does that sound?
R.