#! /usr/bin/perl use warnings; use strict; use Tk; use Tk::ROText; my $logfile = 'E:\apacheweb\8084_develop.perl-community.de\log\error.log'; my $mw = MainWindow->new(); my $buttonFrame = $mw->Frame()->pack(-side => 'top', -fill => 'x', -expand => 1); $buttonFrame->Button(-text => 'Quit', -command => sub { $mw->destroy }) ->pack(-side => 'right'); my $text = $mw->Scrolled('ROText', -scrollbars => 'e', -width => 100, -height => 50, -wrap => 'word') ->pack(-fill => 'both', -expand => 1); $buttonFrame->Button(-text => 'Ans Ende scrollen', -command => sub { $text->see('end') }) ->pack(-side => 'left'); $text->tagConfigure('bold', -font => 'Courier 10 bold'); $text->tagConfigure('red', -background => 'red'); $text->tagConfigure('yellow', -background => 'yellow'); unless (open (LOG, $logfile)) { die "Error: couldn't read '$logfile': $!\n"; } # unless &UpdateFromLog(); MainLoop; close(LOG); # ------------------------------------------------------------ sub UpdateFromLog { seek(LOG, 0, 1); my $found = 0; while () { chomp($_); $found = 1; # try to parse line if (my ($date, $mode, $client, $message) = /^ \[ ([^\]]+) \] \s+ \[ ([^\]]+) \] \s+ \[ ([^\]]+) \] \s+ (.+) $/x) { $text->insert('end', "$date\t$mode\t$client\n", 'bold'); $text->insert('end', "$message\n", $mode eq 'error' ? 'red': 'yellow'); } # if elsif (my ($date3, $mode3, $message3) = /^ \[ ([^\]]+) \] \s+ \[ ([^\]]+) \] \s+ (.+) $/x) { $text->insert('end', "$date3\t$mode3\n", 'bold'); $text->insert('end', "$message3\n", $mode3 eq 'error' ? 'red': 'yellow'); } # elsif elsif (my ($date2, $file, $message2) = /^ \[ ([^\]]+) \] \s+ (\S+) \s+ (.+) $/x ) { $text->insert('end', "$date2\t$file\n", 'bold'); $text->insert('end', "$message2\n", 'yellow'); } # elsif # if not possible, output line else { $text->insert('end', "$_\n"); } # else } $found and $text->see('end'); $mw->after(1000, \&UpdateFromLog); } # UpdateFromLog # ------------------------------------------------------------