diff --git a/lib/SLUB/LZA/Rosetta/TA.pm b/lib/SLUB/LZA/Rosetta/TA.pm index a40853b472fcd855e47a0ffcd5d9bf449c60dfd4..5e6b01838403f7f7caa3e0e2fd41050e0295352d 100644 --- a/lib/SLUB/LZA/Rosetta/TA.pm +++ b/lib/SLUB/LZA/Rosetta/TA.pm @@ -62,7 +62,82 @@ sub sru_search { } else { croak ("Error was: ".$req->status_line()); } +} + +sub helper_scan_log { + my $directory = shift; + my $fh_processing = shift; + 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) { + $fh_processing->( $fh ); + } + undef $fh; + } + return 1; +} +sub trace_log { + my $with_trace=shift; + my $directory = path($config{logdir}); + my $deposit_id; + my $deposit_dir; + my $sip_id; + my $rep_id; + my $ie_pid; + my $searchid = $with_trace; + $searchid=~s/^(REP|SIP|IE)(\d+)$/$2/; + say "SEARCHID=$searchid"; + # match to: + # 1. ... | processing {originalDirName=eb9c1924-4bab-11ec-baca-f69de10fbd49, depositId=422950, ... userName=Goobi_SMA, SIP 422438, producerType=TRUSTED, producerGroup=PG_Goobi, contentStructure=METS, materialFlowSR=0, producerId=264981, contentStructureId=264951, converter_class_name=com.exlibris.dps.deposit.converters.METSCSConverter, retentionPoliciesId=NO_RETENTION} from work queue SIP_LOADING_WORK_QUEUE finished + # 2. ... enqueued {originalDirName=d2cb9509-4bad-11ec-baca-b925eea982a1, depositId=422958, ... userName=Goobi_SMA, sipId=422446, producerType=TRUSTED, producerGroup=PG_Goobi, contentStructure=METS, materialFlowSR=0, producerId=264981, contentStructureId=264951, converter_class_name=com.exlibris.dps.deposit.converters.METSCSConverter, retentionPoliciesId=NO_RETENTION} on work queue V2SL_shr00.SIP_LOADING_WORK_QUEUE + # 3. ... SIP 13156, Deposit Activity ID=17589Properties + + my $sip_rx = qr/(SIP |sipId=)/; + my $pre_rx = qr/\d{4}-\d\d-\d\d \d\d:\d\d:\d\d,\d\d\d INFO .*/; + my $line_rx1= Regexp::Optimizer->new->optimize(qr{^$pre_rx.*(originalDirName=|depositId=|$sip_rx)$searchid}); + my $line_rx2= Regexp::Optimizer->new->optimize(qr{^$pre_rx.*(SIP |Deposit Activity ID=)$searchid}); + my $line_rx3= Regexp::Optimizer->new->optimize(qr{^$pre_rx.*Loaded \d+ files for: .*$searchid}); +# my $search_rxo = Regexp::Optimizer->new->optimize(qr/^$date_rx [^ ]* $level_rx (.*?)$match_rx(.*?)$/); + my $fh_processing_stage1 = sub { + my $fh = shift; + while(<$fh>) { + if ( + (defined $sip_id and defined $deposit_id and defined $deposit_dir) + or (defined $ie_pid and defined $rep_id) + ) { last; } + if (! m/^$pre_rx/) {next;} + if (! m/$searchid/) {next;} + chomp; + if ( m/$line_rx1/ ) { + if (!defined $deposit_dir and m/originalDirName=([^,]*),/) { $deposit_dir = $1; } + if (!defined $sip_id and m/$sip_rx(\d{6}),/) { $sip_id = "SIP" . $2; } + if (!defined $deposit_id and m/depositId=(\d{6}),/) { $deposit_id = $1;} + } elsif (m/$line_rx2/) { + if (!defined $deposit_id and m/Deposit Activity ID=(\d{6})/) { $deposit_id = $1;} + if (!defined $sip_id and m/SIP (\d{6})/) { $sip_id = $1;} + } elsif (m/$line_rx3/) { + if (!defined $rep_id and m/Loaded \d+ files for: (REP\d+)/) { $rep_id = $1;} + if (!defined $ie_pid and m/Loaded \d+ files for: REP\d+ \((IE\d+)/) { $ie_pid = $1;} + } + } + return 1; + }; + helper_scan_log($directory, $fh_processing_stage1); + my $match= "found: DIR=$deposit_dir, DEPOSITID=$deposit_id, SIPID=$sip_id, IEPID=$ie_pid, REPID=$rep_id"; + say "$match"; + say "-"x(length($match)); + # now call scan_log and use own colorizer + my $fh_processing_stage2 = sub { + }; + helper_scan_log($directory, $fh_processing_stage2); } sub scan_log { @@ -77,28 +152,19 @@ sub scan_log { # 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; + my $fh_processing = sub { + my $fh = shift; + while(<$fh>) { + chomp; + if (! m/$search_rxo/) { + #print "no match for '$_'"; + next; } + my $line = $output_filter->( $_ ); + say $line; } - undef $fh; - } + }; + helper_scan_log($directory, $fh_processing); } 1;