Skip to content

Commit

Permalink
Better regex for matching timezone abbreviations. Should fix github i…
Browse files Browse the repository at this point in the history
…ssue #31. Also force the log_line prefix regular expressions to ASCII-only via the 'a' flag
  • Loading branch information
turnstep committed May 2, 2019
1 parent b1276ad commit c12a779
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions tail_n_mail
Expand Up @@ -290,6 +290,8 @@ if (! ref $llprefix) {
$llprefix->{0} = $val;
}

my $timezone_regex = '(?:[A-Z]{3,5}|[+-][0-9][0-9:]*)';

my ($llp_num, $llp1, %pgpidre);
while (($llp_num,$llp1) = each %$llprefix) {

Expand All @@ -315,8 +317,8 @@ while (($llp_num,$llp1) = each %$llprefix) {
$llp1 =~ s/%tb/(\\d\\d\\d\\d\-\\d\\d\-\\d\\d \\d\\d:\\d\\d:\\d\\d\.\\d+)/ and $havetime=1;

## This assumes timestamp comes before the pid!
$llp1 =~ s/%t/(\\d\\d\\d\\d\-\\d\\d\-\\d\\d \\d\\d:\\d\\d:\\d\\d \\w\\w\\w\\w?)/ and $havetime=1;
$llp1 =~ s/%m/(\\d\\d\\d\\d\-\\d\\d\-\\d\\d \\d\\d:\\d\\d:\\d\\d\\.\\d+ \\w\\w\\w\\w?)/ and $havetime=1;
$llp1 =~ s/%t/(\\d\\d\\d\\d\-\\d\\d\-\\d\\d \\d\\d:\\d\\d:\\d\\d $timezone_regex)/ and $havetime=1;
$llp1 =~ s/%m/(\\d\\d\\d\\d\-\\d\\d\-\\d\\d \\d\\d:\\d\\d:\\d\\d\\.\\d+ $timezone_regex)/ and $havetime=1;
if (!$havetime and $pglog !~ /syslog/) {
$llp1 = "()$llp1";
}
Expand Down Expand Up @@ -358,14 +360,14 @@ while (($llp_num,$llp1) = each %$llprefix) {
$havetime = $havepid = 1;
}

$pgpidre{$llp_num}{1} = qr{^($llp1)(.*)};
$pgpidre{$llp_num}{1} = qr{^($llp1)(.*)}a;
$arg{verbose} and $pgmode and warn " Log line prefix regex $llp_num/1: $pgpidre{$llp_num}{1}\n";

## And a separate one for cluster-wide notices

## Items set clusterwide: %t %m %p
$llp2 =~ s/%t/\\d\\d\\d\\d\-\\d\\d\-\\d\\d \\d\\d:\\d\\d:\\d\\d \\w\\w\\w\\w?/;
$llp2 =~ s/%m/\\d\\d\\d\\d\-\\d\\d\-\\d\\d \\d\\d:\\d\\d:\\d\\d\\.\\d+ \\w\\w\\w\\w?/;
$llp2 =~ s/%t/\\d\\d\\d\\d\-\\d\\d\-\\d\\d \\d\\d:\\d\\d:\\d\\d $timezone_regex/;
$llp2 =~ s/%m/\\d\\d\\d\\d\-\\d\\d\-\\d\\d \\d\\d:\\d\\d:\\d\\d\\.\\d+ $timezone_regex/;
$llp2 =~ s/%p/\\d+/;
$llp2 =~ s/%l/\\d+/;
$llp2 =~ s/%q.*//;
Expand All @@ -374,7 +376,7 @@ while (($llp_num,$llp1) = each %$llprefix) {
$llp2 =~ s/%$char//g;
}

$pgpidre{$llp_num}{2} = qr{^$llp2};
$pgpidre{$llp_num}{2} = qr{^$llp2}a;
$arg{verbose} and $pgmode and warn " Log line prefix regex $llp_num/2: $pgpidre{$llp_num}{2}\n";

## And one more for things that throw out everything except the timestamp
Expand All @@ -385,8 +387,8 @@ while (($llp_num,$llp1) = each %$llprefix) {
$llp3 =~ s/\%q.*// or $llp3 =~ s/(.*?%\w).+/$1/;

## Convert %t and %m and %l and %p
$llp3 =~ s/%t/\\d\\d\\d\\d\-\\d\\d\-\\d\\d \\d\\d:\\d\\d:\\d\\d \\w\\w\\w\\w?/;
$llp3 =~ s/%m/\\d\\d\\d\\d\-\\d\\d\-\\d\\d \\d\\d:\\d\\d:\\d\\d\\.\\d+ \\w\\w\\w\\w?/;
$llp3 =~ s/%t/\\d\\d\\d\\d\-\\d\\d\-\\d\\d \\d\\d:\\d\\d:\\d\\d $timezone_regex/;
$llp3 =~ s/%m/\\d\\d\\d\\d\-\\d\\d\-\\d\\d \\d\\d:\\d\\d:\\d\\d\\.\\d+ $timezone_regex/;
$llp3 =~ s/%l/\\d+/;
$llp3 =~ s/%p/\\d+/;

Expand All @@ -396,7 +398,7 @@ while (($llp_num,$llp1) = each %$llprefix) {
## We do a \s* later on, so keep this short
$llp3 =~ s/\s$//;

$pgpidre{$llp_num}{3} = qr{^$llp3};
$pgpidre{$llp_num}{3} = qr{^$llp3}a;
$arg{verbose} and $pgmode and warn " Log line prefix regex $llp_num/3: $pgpidre{$llp_num}{2}\n";

}
Expand Down

0 comments on commit c12a779

Please sign in to comment.