File: logger.pl

package info (click to toggle)
openocd 0.9.0-1%2Bdeb8u1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 25,632 kB
  • sloc: ansic: 275,066; sh: 15,664; tcl: 7,088; asm: 1,913; cpp: 1,671; makefile: 1,200; perl: 717; python: 708; haskell: 35
file content (40 lines) | stat: -rw-r--r-- 917 bytes parent folder | download | duplicates (10)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#!/usr/bin/perl
# logger.pl: masks long meaningless output with pretty lines of dots
#  Details: 1) reads lines from STDIN and echos them on STDOUT,
#           2) print a '.' to STDERR every $N lines.
#           3) print a newline after a sequence of $C dots

use strict;
use warnings;

# make sure all output gets displayed immediately
$| = 1;

# TODO: add -n and -c options w/ zero checks)
# line and column limits
my $N = 10;
my $C = 72;

# current line and column counters
my $n = 0;
my $c = 0;

# read all lines from STDIN
while (<STDIN>)
{
	# echo line to output
	print STDOUT $_;
	# echo line to console if it is important
	if (/(Warning|Error)/) {
		print STDERR "\n" if $c;
		print STDERR $_;
		$c = 0;
	}
	# only display progress every Nth step
	next if ++$n % $N;
	print STDERR ".";
	# wrap at column C to provide fixed-width rows of dots
	print STDERR "\n" unless ++$c % $C;
}

print STDERR "\n" if $c;