Chat Log Filter

Chat Log Filter

Various things about Spring that do not fit in any of the other forums listed below, including forum rules.

Moderator: Moderators

Post Reply
User avatar
SinbadEV
Posts: 6475
Joined: 02 May 2005, 03:56

Chat Log Filter

Post 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"
Tobi
Spring Developer
Posts: 4598
Joined: 01 Jun 2005, 11:36

Post 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 :)
User avatar
Dragon45
Posts: 2883
Joined: 16 Aug 2004, 04:36

Post 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
greenail
Spring Developer
Posts: 80
Joined: 13 Dec 2005, 20:16

Post by greenail »

Code: Select all

#!/usr/bin/perl

&startFlameWar;

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

User avatar
FLOZi
MC: Legacy & Spring 1944 Developer
Posts: 6242
Joined: 29 Apr 2005, 01:14

Post by FLOZi »

Code: Select all

#!/usr/bin/python

def startFlameWar():
  while True:
    print 'Python > Perl!'
:wink:
User avatar
diggz2k
Posts: 208
Joined: 04 Mar 2005, 06:34

Post by diggz2k »

nerds heh.
User avatar
SwiftSpear
Classic Community Lead
Posts: 7287
Joined: 12 Aug 2005, 09:29

Post by SwiftSpear »

I can't tell if I should be locking this :P
Post Reply

Return to “General Discussion”