]> granicus.if.org Git - pgbadger/commitdiff
Change syslog parsing regex to allow log timestamp in log_line_prefix
authorDarold <gilles@darold.net>
Sun, 1 Jul 2012 08:59:46 +0000 (10:59 +0200)
committerDarold <gilles@darold.net>
Sun, 1 Jul 2012 08:59:46 +0000 (10:59 +0200)
pgbadger

index d87cafe42ff6066c92bb4b9d72fa85d52a7ac028..a427f55663cef18ac0f6662e4f1712f8cbe3328d 100755 (executable)
--- a/pgbadger
+++ b/pgbadger
@@ -384,7 +384,8 @@ foreach $logfile (@log_files) {
 
                # Parse syslog lines
                if ($format eq 'syslog') {
-                       if ($line =~ /^(...)\s+(\d+)\s+(\d+):(\d+):(\d+)\s+([^\s]+)\s+([^\[]+)\[(\d+)\]:\s+\[([0-9\-]+)\]\s*([^\s]*)\s+([A-Z]+:)\s+(.*)/) {
+
+                       if ($line =~ /^(...)\s(\d+)\s(\d+):(\d+):(\d+)\s([^\s]+)\s([^\[]+)\[(\d+)\]:\s\[([0-9\-]+)\]\s*(.*?)\s+([A-Z]+:)\s+(.*)/) {
                                # skip non postgresql lines
                                next if ($7 ne $ident);
                                # Syslog do not have year information, so take care of year overlapping
@@ -398,7 +399,7 @@ foreach $logfile (@log_files) {
                                last if ($to && ($to < $cur_date));
                                # Process the log line
                                &parse_query($tmp_year, $month_abbr{$1}, sprintf("%02d", $2), $3, $4, $5, $6, $8, $9, $10, $11,$12);
-                       } elsif ($line =~ /^(...)\s+(\d+)\s+(\d+):(\d+):(\d+)\s+([^\s]+)\s+([^\[]+)\[(\d+)\]:\s+\[([0-9\-]+)\]\s+(#011)[\t\s]*(.*)/) {
+                       } elsif ($line =~ /^(...)\s(\d+)\s(\d+):(\d+):(\d+)\s([^\s]+)\s([^\[]+)\[(\d+)\]:\s\[([0-9\-]+)\]\s+[^\#]*(#011)[\t\s]*(.*)/) {
 
                                $cur_info{query} .= "\n" . $11;
                        } else {
@@ -408,7 +409,7 @@ foreach $logfile (@log_files) {
                } elsif ($format eq 'stderr') {
 
                        # Parse stderr lines
-                       if ($line =~ /(\d+)-(\d+)-(\d+)\s+(\d+):(\d+):(\d+)\s+([^\s]+)\s+\[(\d+)\]:\s+\[([0-9\-]+)\]\s*([^\s]*)\s+([A-Z]+:)\s+(.*)/) {
+                       if ($line =~ /(\d+)-(\d+)-(\d+)\s(\d+):(\d+):(\d+)\s([^\s]+)\s\[(\d+)\]:\s\[([0-9\-]+)\]\s*(.*?)\s+([A-Z]+:)\s+(.*)/) {
                                # Skip unwanted lines
                                my $cur_date = "$1$2$3$4$5$6";
                                next if ($from && ($from > $cur_date));
@@ -2438,7 +2439,11 @@ sub parse_query
        # Extract user and database information from the logprefix part
        my $t_dbname = '';
        my $t_dbuser = '';
+       # Remove log_line_prefix timestamp and extra space character
+       $t_logprefix =~ s/(\d+)-(\d+)-(\d+)\s(\d+):(\d+):(\d+)\s([^\s]+)//;
        $t_logprefix =~ s/\s+$//;
+       $t_logprefix =~ s/^\s+//;
+
        if ($t_logprefix) {
                # User defined regex
                if ($regex_prefix_dbuser) {
@@ -2789,11 +2794,11 @@ sub autodetect_format
                next if (!$line);
                $nline++;
                # Is syslog lines ?
-               if ($line =~ /^...\s+\d+\s+\d+:\d+:\d+\s+[^\s]+\s+[^\[]+\[\d+\]:\s+\[[0-9\-]+\]\s+[^:]+:\s+duration:/) {
+               if ($line =~ /^...\s\d+\s\d+:\d+:\d+\s[^\s]+\s[^\[]+\[\d+\]:\s\[[0-9\-]+\]\s.*:\s+duration:/) {
                        $fmt = 'syslog';
                        $nfound++;
                # Is stderr lines
-               } elsif ($line =~ /\d+-\d+-\d+\s+\d+:\d+:\d+\s+[^\s]+\s+\[\d+\]:\s+\[[0-9\-]+\]\s+[^:]+:\s+duration:/) {
+               } elsif ($line =~ /\d+-\d+-\d+\s\d+:\d+:\d+\s[^\s]+\s\[\d+\]:\s\[[0-9\-]+\]\s.*:\s+duration:/) {
                        $fmt = 'stderr';
                        $nfound++;
                } elsif ($line =~ tr/,/,/ >= 12) {