From 41e9cdda9f4840cb69483dc9e8afb49ef1d60afb Mon Sep 17 00:00:00 2001 From: Don Armstrong Date: Sat, 16 Aug 2008 12:16:42 -0700 Subject: [PATCH] generalize append_to_log --- Debbugs/Control.pm | 33 ++++++++++++++++++++++++++------- 1 file changed, 26 insertions(+), 7 deletions(-) diff --git a/Debbugs/Control.pm b/Debbugs/Control.pm index 61e4c29e..7cb645ed 100644 --- a/Debbugs/Control.pm +++ b/Debbugs/Control.pm @@ -895,14 +895,20 @@ sub append_action_to_log{ action => {type => SCALAR, }, requester => {type => SCALAR, + default => '', }, request_addr => {type => SCALAR, + default => '', }, location => {type => SCALAR, optional => 1, }, message => {type => SCALAR|ARRAYREF, + default => '', }, + desc => {type => SCALAR, + default => '', + }, get_lock => {type => BOOLEAN, default => 1, }, @@ -917,17 +923,30 @@ sub append_action_to_log{ } my $log = IO::File->new(">>$log_location") or die "Unable to open $log_location for appending: $!"; - print {$log} "\6\n". + my $msg = "\6\n". "\n". - "".html_escape($param{action})."\n". - "Request was from ".html_escape($param{requester})."\n". - "to ".html_escape($param{request_addr}).". \n". - "\3\n". - "\7\n",escape_log(make_list($param{message})),"\n\3\n" + "".html_escape($param{action})."\n"; + if (length $param{requester}) { + $msg .= "Request was from ".html_escape($param{requester})."\n"; + } + if (length $param{request_addr}) { + $msg .= "to ".html_escape($param{request_addr}).""; + } + if (length $param{desc}) { + $msg .= ":
\n$param{desc}\n"; + } + else { + $msg .= ".\n"; + } + $msg .= "\3\n"; + if ((ref($param{message}) and @{$param{message}}) or length($param{message})) { + $msg .= "\7\n".join('',escape_log(make_list($param{message})))."\n\3\n" or die "Unable to append to $log_location: $!"; + } + print {$log} $msg or die "Unable to append to $log_location: $!"; close $log or die "Unable to close $log_location: $!"; if ($param{get_lock}) { - unlockfile(); + unfilelock(); } -- 2.39.5