Akron | f80da9a | 2021-02-23 12:12:13 +0100 | [diff] [blame] | 1 | #!/usr/bin/env perl |
| 2 | use Mojo::Base -strict; |
| 3 | use Mojo::File qw'path'; |
| 4 | |
| 5 | our @ARGV; |
| 6 | my ($unable, $unable_substring, $unable_offsets) = (0,0,0); |
| 7 | |
| 8 | my $file = path($ARGV[0]); |
| 9 | my $out_fh = path($file->dirname)->child( |
| 10 | $file->basename('.log') . '-slim.log' |
| 11 | )->open('>'); |
| 12 | |
| 13 | my $fh = $file->open('<'); |
| 14 | |
| 15 | # Iterate over file |
| 16 | while (!eof($fh)){ |
| 17 | local $_ = <$fh>; |
| 18 | |
| 19 | if ($_ =~ qr!(?: Processed)! && $_ !~ qr!:1\/!) { |
| 20 | next; |
| 21 | }; |
| 22 | |
| 23 | if ($_ =~ qr! Unable to process !) { |
| 24 | $unable++; |
| 25 | next; |
| 26 | } |
| 27 | elsif ($_ =~ qr! Tokenization with failing offsets !) { |
| 28 | $unable_offsets++; |
| 29 | next; |
| 30 | } |
| 31 | elsif ($_ =~ qr! Unable to find substring !) { |
| 32 | $unable_substring++; |
| 33 | next; |
| 34 | } |
| 35 | elsif ($_ =~ qr!^Done\.$!) { |
| 36 | my $str = 'Done.'; |
| 37 | $str .= ' [!Process: ' . $unable . ']' if $unable; |
| 38 | $str .= ' [!Offstes: ' . $unable_offsets . ']' if $unable_offsets; |
| 39 | $str .= ' [!Substring: ' . $unable_substring . ']' if $unable_substring; |
| 40 | $unable = 0; |
| 41 | $unable_substring = 0; |
| 42 | $unable_offsets = 0; |
| 43 | print $out_fh "## $str\n"; |
| 44 | next; |
| 45 | }; |
| 46 | |
| 47 | if ($_ =~ qr! Unable to (?:process|find substring) !) { |
| 48 | next; |
| 49 | } |
| 50 | elsif ($_ =~ qr!substr outside of string!) { |
| 51 | next; |
| 52 | } |
| 53 | elsif ($_ =~ qr!with failing offsets!) { |
| 54 | next; |
| 55 | } |
| 56 | elsif ($_ =~ qr! in \/opt\/korap!) { |
| 57 | next; |
| 58 | }; |
| 59 | |
| 60 | print $out_fh $_; |
| 61 | }; |
| 62 | |
| 63 | $out_fh->close; |
| 64 | $fh->close; |
| 65 | |
| 66 | __END__ |
| 67 | |
| 68 | =pod |
| 69 | |
| 70 | $ slim_korapxml2krill mylog.log |
| 71 | |
| 72 | =cut |