X-Git-Url: https://defaria.com/gitweb/?a=blobdiff_plain;f=lib%2FSpeak.pm;h=c98feca6ee50a43d4e9ddd1760ab015b4b846fd6;hb=75f06ef1cd56d531eb9ae086618bce3ff6aaa510;hp=7003f209803a5a186724907d9886e909e1ed534e;hpb=b9581bfa0e37aafedf42ccbb1c514b572aa0d8d3;p=clearscm.git diff --git a/lib/Speak.pm b/lib/Speak.pm index 7003f20..c98feca 100644 --- a/lib/Speak.pm +++ b/lib/Speak.pm @@ -83,7 +83,7 @@ Otherwise the text in the clipboard will be used. =item $log -If provided, errors and messages will be logged to the logfile, otherwise stdout +If provided, errors and messages will be logged to the logfile, otherwise to speak.log =back @@ -103,13 +103,16 @@ Returns: =cut + $log = Logger->new( + path => '/var/local/log', + name => 'speak', + timestamped => 'yes', + append => 1, + ) unless $log; + if (-f "$FindBin::Bin/../data/shh") { $msg .= ' [silent shh]'; - if ($log) { - $log->msg($msg); - } else { - verbose $msg; - } # if + $log->msg($msg); return; } # if @@ -120,40 +123,15 @@ Returns: # Handle the case where $msg is a filehandle $msg = <$msg> if ref $msg eq 'GLOB'; - # We can't have two speakers going at the same time so if we have an error - # backoff a little and try again. - my $attempts = 0; - my $maxretries = 3; - - my ($status, @output); - # Log message to log file if $log was passed in. - $log->msg($msg) if $log; - - while ($attempts++ < $maxretries) { - ($status, @output) = Execute "/usr/local/bin/gt \"$msg\""; - - if ($status) { - my $errmsg = "Unable to speak (Status: $status) - " . join "\n", @output; - - if ($log) { - $log->err($errmsg); - } else { - error $errmsg; - } # if + $log->msg($msg); - sleep int rand 10; - } else { - return; - } # if - } # while + my ($status, @output) = Execute "/usr/local/bin/gt \"$msg\""; - my $errmsg = 'Maximum retries exceeded - terminating'; + if ($status) { + my $errmsg = "Unable to speak (Status: $status) - " . join "\n", @output; - if ($log) { - $log->err($errmsg, $status); - } else { - error $errmsg, $status; + $log->err($errmsg); } # if return;