Просмотр исходного кода

Added support to set a "logsuffix" variable

Default is to be unset, which will use no custom sorting
See CONFIG-README for more details
sbingner 25 лет назад
Родитель
Сommit
829bc5672f
2 измененных файлов с 48 добавлено и 1 удалено
  1. 5 0
      docs/CONFIG-README
  2. 43 1
      modules/Pisg/Parser/Logfile.pm

+ 5 - 0
docs/CONFIG-README

@@ -88,6 +88,11 @@ channel             The name of your channel. E.g. '#mychannel'
 
 
 logfile             The exact filename of the logfile. E.g. 'mylog.log'
 logfile             The exact filename of the logfile. E.g. 'mylog.log'
 
 
+logsuffix           Regexes to sort logfiles by in format month||day||year
+                    Note: example will work for eggdrop's default format
+                    Example: logsuffix="\.\d\d([A-Za-z]+)\d\d\d\d||\.(\d\d)[A-Za-z]+\d\d\d\d||\.\d\d[A-Za-z]+(\d\d\d\d)"
+                    default: unset
+
 format              The logfile format. See FORMATS file for supported formats
 format              The logfile format. See FORMATS file for supported formats
 
 
 network             Network the channel is using. E.g. 'Undernet'
 network             Network the channel is using. E.g. 'Undernet'

+ 43 - 1
modules/Pisg/Parser/Logfile.pm

@@ -122,7 +122,49 @@ sub _parse_dir
         monocount  => 0,
         monocount  => 0,
         oldtime    => 24
         oldtime    => 24
     );
     );
-    foreach my $file (sort @filesarray) {
+    if (defined $self->{cfg}->{logsuffix}) {
+        my @temparray;
+        my %months = (
+            'jan'	=> '0',
+            'feb'	=> '1',
+            'mar'	=> '2',
+            'apr'	=> '3',
+            'may'	=> '4',
+            'jun'	=> '5',
+            'jul'	=> '6',
+            'aug'	=> '7',
+            'sep'	=> '8',
+            'oct'	=> '9',
+            'nov'	=> '10',
+            'dec'	=> '11',
+        );
+        my ($mreg, $dreg, $yreg) = split(/\|\|/, $self->{cfg}->{logsuffix});
+        my (@month, @day, @year);
+        for my $file (@filesarray) {
+            $file =~ /$mreg/;
+            my $month = $1;
+            $month = lc $month;
+            $month = $months{$month}
+                if (defined $months{$month});
+            push @month, $month;
+            $file =~ /$dreg/;
+            push @day, $1;
+            $file =~ /$yreg/;
+            push @year, $1;
+        }
+        my @newarray = @filesarray[ sort {
+                                    $year[$a] <=> $year[$b]
+                                               ||
+                                    $month[$a] <=> $month[$b]
+                                               ||
+                                    $day[$a] <=> $day[$b]
+                                 } 0..$#filesarray ];
+        @filesarray = @newarray;
+    } else {
+        @filesarray = sort @filesarray;
+    }
+
+    foreach my $file (@filesarray) {
         $file = $self->{cfg}->{logdir} . $file;
         $file = $self->{cfg}->{logdir} . $file;
         $self->_parse_file($stats, $lines, $file, \%state);
         $self->_parse_file($stats, $lines, $file, \%state);
     }
     }