Skip to content
Snippets Groups Projects
Commit 3d0599db authored by Andreas Romeyke's avatar Andreas Romeyke
Browse files

- added Regexp::Optimizer

- added IO::Zlib
- fixed loading of config at begin
- added scan_log()
parent 83d42b17
Branches
Tags
No related merge requests found
......@@ -7,14 +7,20 @@ use YAML qw(LoadFile);
use LWP::UserAgent;
use Carp qw( croak );
use feature qw(say);
use Regexp::Optimizer;
use IO::Zlib;
our %config;
my $home = path( $ENV{'HOME'} );
if ($home->is_dir() && !$home->is_rootdir) {
my $config_path = $home->child('.config')->child('ta-tool.rc');
our $config_file = $config_path;
if ($config_path->is_file) {
%config = YAML::LoadFile($config_path);
BEGIN{
my $home = path($ENV{'HOME'});
if ($home->is_dir() && !$home->is_rootdir) {
my $config_path = $home->child('.config')->child('ta-tool.rc');
our $config_file = $config_path;
if ($config_path->is_file) {
if (1) { say "DEBUG: loading config from '$config_file'"; }
%config = YAML::LoadFile($config_path);
}
}
}
......@@ -60,4 +66,40 @@ sub sru_search {
}
sub scan_log {
my $date_rx=shift;
my $level_rx=shift;
my $match_rx=shift;
my $output_filter=shift;
# open dir from config{$logdir}
# for all files matching server.log*; do
# read lines
# filter lines
# return
my $directory = path($config{logdir});
my $search_rxo = Regexp::Optimizer->new->optimize(qr/^$date_rx [^ ]* $level_rx (.*?)$match_rx(.*?)$/);
for ($directory->children( qr/^server.log/ )) {
my $file = $_;
if (!$file->is_file) { next; }
my $fh;
if ($file =~ m/\.gz$/) {
$fh = IO::Zlib->new("$file", "rb");
} else {
$fh = $file->openr;
}
if (defined $fh) {
while(<$fh>) {
chomp;
if (! m/$search_rxo/) {
#print "no match for '$_'";
next;
}
my $line = $output_filter->( $_ );
say $line;
}
}
undef $fh;
}
}
1;
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment