SVN: toys/rsget.pl/RSGet/Line.pm

sparky sparky at pld-linux.org
Mon Jul 12 01:24:28 CEST 2010


Author: sparky
Date: Mon Jul 12 01:24:28 2010
New Revision: 11651

Modified:
   toys/rsget.pl/RSGet/Line.pm
Log:
- added file logging and logfile setting


Modified: toys/rsget.pl/RSGet/Line.pm
==============================================================================
--- toys/rsget.pl/RSGet/Line.pm	(original)
+++ toys/rsget.pl/RSGet/Line.pm	Mon Jul 12 01:24:28 2010
@@ -10,6 +10,12 @@
 use RSGet::Tools;
 set_rev qq$Id$;
 
+def_settings(
+	logfile => {
+		desc => "Select log file, empty value disables logging.",
+		type => "PATH",
+	},
+);
 my $term_size_columns;
 my $term_size_rows;
 
@@ -33,6 +39,7 @@
 our @dead;
 our $dead_change = 0;
 our %status;
+my $log_fh;
 my $last_line = 0;
 
 my $last_day = -1;
@@ -60,6 +67,8 @@
 	}
 
 	print @print unless $nooutput;
+	print $log_fh join "\n", @newdead, ''
+		if $log_fh;
 	if ( @newdead ) {
 		push @dead, @newdead;
 		$dead_change++;
@@ -196,11 +205,21 @@
 	hadd( \%status, @_ );
 }
 
+END {
+	close $log_fh if $log_fh;
+}
+
 sub init
 {
 	$nooutput = shift;
 	$| = 1;
 
+	if ( my $file = setting( "logfile" ) ) {
+		$log_fh = undef;
+		open $log_fh, ">>", $file
+			or die "Cannot open log file $file: $!\n";
+	}
+
 	$SIG{__WARN__} = sub {
 		new RSGet::Line( "WARNING: ", shift );
 		update();


More information about the pld-cvs-commit mailing list