Page 1 of 1

Chat Log Filter

Posted: 24 Feb 2006, 03:13
by SinbadEV
I had my friend write me a pearl script to filter the infolog.txt and display it in a command window... useful for running in the background so you can see what people are saying when the screen is too full of errors-

Code: Select all

#!/usr/bin/perl

use strict;
use warnings; 

my $sLogFile		= $ARGV[0];
my $iRefreshRate	= $ARGV[1];
my $bFilterChat		= $ARGV[2];
my $bFilterOther	= $ARGV[3];

print "Log file: $sLogFile\n";
print "Refresh Rate: $iRefreshRate\n";
print "Filter Chat: $bFilterChat\t(0 = Don't filter; anything else = filter)\n";
print "Filter Other: $bFilterOther\t(same as above)\n";

my @myFile;
my $curOffset = 0;
my $i;
my $lastMyFileSize = 0;
my $newMyFileSize = 0;

for (;;) {
	$newMyFileSize = 0;
	
	open FILEIN, $sLogFile || die "Can't open file \"$sLogFile\": $!";
		foreach (<FILEIN>) {
			@myFile[$newMyFileSize] = $_;
			$newMyFileSize++;
		}
	close FILEIN;

	# Hurm... someone call the cops... taspring is a pice of crap, written in spagetti... i meen... The devil's C++
	# ie: log file was wrighten too, instead of appended
	if ($lastMyFileSize > $newMyFileSize) {
		print "Error, ta spring gayness has maxed out!\n";
		print "Please wait while a real programmer fixes the issue ~.~\n";

		# Reset offset to redraw entire log
		$curOffset = 0;
	}

	$lastMyFileSize = $newMyFileSize;
	
	# This (along with $curOffset) only prints new lines
	for ($i=$curOffset; $i < $newMyFileSize; $i++) {
		my $curLine = @myFile[$i];
		
		# If we found a blank line, it's probably because of syncronization
		# ie: log file is being written to, but has not finished writing the line
		if ($curLine =~ /^\s+$/) {
			# Be carful now... Don't hit a never ending loop, or miss a line...
			#
			# Make sure we're on the last line in the file...
			if ($i != (@myFile - 1)) {
				# Ok, not the last line, just a blank line... do jack
			} else {
				# Hokay... our offset must not change, to cause the line to be re-read
				$i = $curOffset;
			}
		} else {
			# Print other?
			if ($bFilterOther == 0) {
				if ($curLine =~ /^[^<[]/) {
					print $curLine;
				}
			}

			# Print chat?
			if ($bFilterChat == 0) {
				if ($curLine =~ /^(\<|\[)/) {
					print $curLine;
				}
			}
		}
	}

	# If we grow $i, we need to grow the offset; otherwise we just get old offset :P
	$curOffset = $i;

	sleep($iRefreshRate);
}

I run a batch file like this:

Code: Select all

start test.pl infolog.txt 1 1 0
start test.pl infolog.txt 1 0 1
You'll need active Perl.

Author DeadRAM
Distributed Under the NFB Licence:
"Don't Do Stupid Stuff It's Public"

Posted: 24 Feb 2006, 10:55
by Tobi
You should have grabbed tail from some unix tools for windows package. You'd just have to open a terminal and type tail -f infolog.txt for the same effect as the above script. In that case, pick grep too and use it's regular expression matching to filter out certain things.

But nyways, since you friend already wrote it, I guess it doesn't matter :)

Posted: 24 Feb 2006, 15:57
by Dragon45
It's "Perl", not "pearl".

But it doesn't matter because evrey time you use Perl, God kills an Ethiopian.











Remember Kids:




PERL SUCKS

Posted: 24 Feb 2006, 16:21
by greenail

Code: Select all

#!/usr/bin/perl

&startFlameWar;

sub startFlameWar()
{
while(1)
    {
    print "PERL ROCKS YOUR WORLD\n";
    }
}


Posted: 24 Feb 2006, 17:03
by FLOZi

Code: Select all

#!/usr/bin/python

def startFlameWar():
  while True:
    print 'Python > Perl!'
:wink:

Posted: 24 Feb 2006, 19:05
by diggz2k
nerds heh.

Posted: 24 Feb 2006, 23:20
by SwiftSpear
I can't tell if I should be locking this :P