Here is a version with fileevent that works (with some problems):
# insert widget code here open (LOG, "tail -f log.log|") || die "Nope : $!"; $mw->fileevent(\*LOG, 'readable', \&insert_lines); MainLoop(); sub insert_lines { my $line; if(defined($line = <LOG>)){ if( $line =~ /(CRITICAL|MAJOR)/){ $text->insert('end',$line,$1); } else { $text->insert('end',$line); } }else{ $mw->fileevent(\*LOG, 'readable',''); } }
The problem being (on my machine) that it sometimes doesn't update even there is data waiting on the pipe. Even the first time it only gets the first line of the tail, then nothing until another line is added to the file (then it gets the remainder of the tail and the newer line). You could work around this using repeat() to check the file yourself every so often -- here's a quicky example that might suffice for your needs:
# insert widget code here open (LOG, "log.log") || die "Nope : $!"; load_file(5); $mw->repeat(5000,\&tail_file); # check every 5 seconds MainLoop(); sub load_file { my $n = shift || 10; #how many lines to initially tail my @tail; while(<LOG>){ shift @tail if $#tail > $n; push @tail, $_; } for(@tail){ if(/(CRITICAL|MAJOR)/){ $text->insert('end',$_,$1); } else { $text->insert('end',$_); } } } sub tail_file { seek(LOG,0,1); while(<LOG>){ if(/(CRITICAL|MAJOR)/){ $text->insert('end',$_,$1); } else { $text->insert('end',$_); } } }
In reply to Re: Re: Re: TK Problem (me again)
by danger
in thread TK Problem (me again)
by locked_user mr_leisure
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |