LogoopenSUSE Build Service > Projects
Sign Up | Log In

View File phunkytailf.pl of Package phunkytailf (Project home:draht)

#!/usr/bin/perl
@logs = @ARGV;
@colors = (1,2,3,5,6,7);
$colornum = 0;
$esc = chr(27);
$colorend = $esc."[0m";

foreach $log (@logs) {
	$loghandle{$log} = "$LOG.$log";
	$loghandle = $loghandle{$log};
	open($loghandle{$log}, $log) || die "couldn't open $log: $!";
	seek($loghandle{$log},-1000,2);
	$j = <$loghandle>;
	($j, $oldinode{$log}) = stat $log;

	$color{$log} = $colors[$colornum];
	$colorstart{$log} = $esc."[1;3".$colors[$colornum]."m";
	printf "%scolors[%d] = %d => %s%s\n", $colorstart{$log}, $colornum, $colors[$colornum], $log, $colorend;

	$colornum++;
	if ($colornum == @colors) {
		$colornum = 0;
	}
}

$old = select STDIN; $| = 1;
select STDOUT;       $| = 1;
select $old;

for (;;) {
	foreach $log (@logs) {
		$loghandle = $loghandle{$log};
		while(<$loghandle>) {
			chop;
			print $colorstart{$log},$_,$colorend,"\n";
			$i{$log} = 60;
		}
		if($i{$log}-- < 0) {
			$i{$log} = 30;
			($j, $newinode,$mode,$nlink,$uid,$gid,$rdev,$size) = stat $log;
			if ($newinode != $oldinode{$log} & $size) {
				print "Rotation of $log!\n";
				close $loghandle{$log};
				open ($loghandle{$log}, $log);
# shoudn't need this here..	seek($loghandle{$log}, 0, 1);
				$oldinode{$log} = $newinode;
			}
		}
		seek($loghandle{$log}, 0, 1);
	}

	select(undef, undef, undef, 0.2);
#	sleep 1;
}