aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlexander Moisseev <moiseev@mezonplus.ru>2018-03-17 19:03:53 +0300
committerAlexander Moisseev <moiseev@mezonplus.ru>2018-03-17 19:03:53 +0300
commit7635433089aa34dd21b4df7a74ece6e78b41e0ef (patch)
tree58a6f39ea952d72d241fd68ec8abcf2e965b4d13
parent2f60c72b00c026b4b34160bc599a121a3c2662a0 (diff)
downloadrspamd-7635433089aa34dd21b4df7a74ece6e78b41e0ef.tar.gz
rspamd-7635433089aa34dd21b4df7a74ece6e78b41e0ef.zip
[Feature] rspamd_stats: Output progress info on STDERR
and only if it is connected to the terminal
-rwxr-xr-xutils/rspamd_stats.pl23
1 files changed, 10 insertions, 13 deletions
diff --git a/utils/rspamd_stats.pl b/utils/rspamd_stats.pl
index 102654dba..3a8affce1 100755
--- a/utils/rspamd_stats.pl
+++ b/utils/rspamd_stats.pl
@@ -113,17 +113,16 @@ elsif ( -d "$log_file" ) {
open( $rspamd_log, "-|", "$dc $log_dir/$_" )
or die "cannot execute $dc $log_dir/$_ : $!";
- if (!$json) {
- printf "\033[J Parsing log files: [%d/%d] %s\033[G", $log_file_num++, scalar @logs, $_;
- $spinner_update_time = 0; # Force spinner update
- &spinner;
- }
+ printf {interactive(*STDERR)} "\033[J Parsing log files: [%d/%d] %s\033[G", $log_file_num++, scalar @logs, $_;
+ $spinner_update_time = 0; # Force spinner update
+ &spinner;
&ProcessLog;
close($rspamd_log)
or warn "cannot close $dc $log_dir/$_: $!";
}
+ print {interactive(*STDERR)} "\033[J\033[G"; # Progress indicator clean-up
}
else {
my $ext = ($log_file =~ /[^.]+\.?([^.]*?)$/)[0];
@@ -630,13 +629,11 @@ sub GetLogfilesList {
splice( @logs, $exclude_logs, $num_logs ||= @logs - $exclude_logs );
# Loop through array printing out filenames
- if (!$json) {
- print "\nLog files to process:\n";
- foreach my $file (@logs) {
- print " $file\n";
- }
- print "\n";
+ print {interactive(*STDERR)} "\nLog files to process:\n";
+ foreach my $file (@logs) {
+ print {interactive(*STDERR)} " $file\n";
}
+ print {interactive(*STDERR)} "\n";
return @logs;
}
@@ -701,9 +698,9 @@ sub numeric {
sub spinner {
my @spinner = qw{/ - \ |};
return
- if ( $json || ( time - $spinner_update_time ) < 1 );
+ if ( ( time - $spinner_update_time ) < 1 );
$spinner_update_time = time;
- printf "%s\r", $spinner[ $spinner_update_time % @spinner ];
+ printf {interactive(*STDERR)} "%s\r", $spinner[ $spinner_update_time % @spinner ];
select()->flush();
}