Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re^3: question on log_watcher input

by marinersk (Priest)
on Sep 10, 2015 at 00:09 UTC ( [id://1141486]=note: print w/replies, xml ) Need Help??


in reply to Re^2: question on log_watcher input
in thread question on log_watcher input

Perhaps this will give you some ideas. Using the following test data:

Something bad happened with orchestral stuff at com.orchestral.rhapsody.execution.route.spi.conditions.ConnectorExe +cutor.accepts(ConnectorExecutor.java:4) and I don't know what to do about this execution failure but execution of orchestral stuff is important

This script:

#!/usr/bin/perl use strict; use warnings; # Create test data, change logic a smidge if reading from monster log +file my @LogBuffer = ( "Something bad happened with orchestral stuff", "at com.orchestral.rhapsody.execution.route.spi.conditions.Connect +orExecutor.accepts(ConnectorExecutor.java:4)", "and I don't know what to do about this execution failure", "but execution of orchestral stuff is important", ); # Convert search strings into regular expressions my @ParseRegExElements = (); foreach my $ParseString (@ARGV) { my $RequestedRegEx = quotemeta $ParseString; push @ParseRegExElements, $RequestedRegEx; } # To check for them only in the order given: print "\n-----[ Must occur in the order given ]-----\n"; { my $ParseRegEx = join '.*', @ParseRegExElements; my @LogMatch = grep /$ParseRegEx/, @LogBuffer; foreach (@LogMatch) { print "Match: [$_]\n"; } } # To check for them in any order: print "\n-----[ May occur in any order ]-----\n"; { my $SearchDirection = (-1); # If == -1: Searching @LogBuffer +into @LogMatch # If == 0: Searching @LogMatch i +nto @NewMatch # If == 1: Searching @NewMatch i +nto @LogMatch my @LogMatch = (); my @NewMatch = (); foreach my $ParseRegEx (@ParseRegExElements) { if ($SearchDirection == (-1) ) { @LogMatch = grep /$ParseRegEx/, @LogBuffer; } elsif ($SearchDirection == 0) { @NewMatch = grep /$ParseRegEx/, @LogMatch; } elsif ($SearchDirection == 1) { @LogMatch = grep /$ParseRegEx/, @NewMatch; } # Toggle Direction $SearchDirection = 1 - abs($SearchDirection); } if ($SearchDirection == 0) { foreach (@LogMatch) { print "Match: [$_]\n"; } } else { foreach (@NewMatch) { print "Match: [$_]\n"; } } } print "\n-----[ Done]-----\n"; exit; __END__

Produced these results:

D:\PerlMonks>parse1.pl orchestral execution -----[ Must occur in the order given ]----- Match: [at com.orchestral.rhapsody.execution.route.spi.conditions.Con +nectorExecutor.accepts(ConnectorExecutor.java:4)] -----[ May occur in any order ]----- Match: [at com.orchestral.rhapsody.execution.route.spi.conditions.Con +nectorExecutor.accepts(ConnectorExecutor.java:4)] Match: [but execution of orchestral stuff is important] -----[ Done]-----

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1141486]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (4)
As of 2024-03-29 05:09 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found