]> granicus.if.org Git - pgbadger/commitdiff
Add support to %n log_line_prefix option for Unix epoch (PG 9.6).
authorDarold Gilles <gilles@darold.net>
Mon, 12 Oct 2015 19:17:25 +0000 (21:17 +0200)
committerDarold Gilles <gilles@darold.net>
Mon, 12 Oct 2015 19:17:25 +0000 (21:17 +0200)
pgbadger

index 0020cc47e0df19b4fad3eb0b866394fe3813cc04..fabccbb9e9564bd34fcd1e5eb7dfecaf5a5096d3 100755 (executable)
--- a/pgbadger
+++ b/pgbadger
@@ -2410,6 +2410,11 @@ sub process_file
                                                $prefix_vars{'t_timestamp'} = $prefix_vars{'t_mtimestamp'};
                                        } elsif (!$prefix_vars{'t_timestamp'} && $prefix_vars{'t_session_timestamp'}) {
                                                $prefix_vars{'t_timestamp'} = $prefix_vars{'t_session_timestamp'};
+                                       } elsif (!$prefix_vars{'t_timestamp'} && $prefix_vars{'t_epoch'}) {
+                                               $prefix_vars{'t_timestamp'} = strftime("%Y-%m-%d %H:%M:%S", CORE::localtime($prefix_vars{'t_epoch'}));
+                                               if ($prefix_vars{'t_epoch'} =~ /^\d{10}(\.\d{3})$/) {
+                                                       $prefix_vars{'t_timestamp'} .= $1;
+                                               }
                                        }
                                        ($prefix_vars{'t_year'}, $prefix_vars{'t_month'}, $prefix_vars{'t_day'}, $prefix_vars{'t_hour'},
                                                $prefix_vars{'t_min'}, $prefix_vars{'t_sec'}) = ($prefix_vars{'t_timestamp'} =~ $time_pattern);
@@ -2755,6 +2760,11 @@ sub check_file_changed
                                        $prefix_vars{'t_timestamp'} = $prefix_vars{'t_mtimestamp'};
                                } elsif (!$prefix_vars{'t_timestamp'} && $prefix_vars{'t_session_timestamp'}) {
                                        $prefix_vars{'t_timestamp'} = $prefix_vars{'t_session_timestamp'};
+                               } elsif (!$prefix_vars{'t_timestamp'} && $prefix_vars{'t_epoch'}) {
+                                       $prefix_vars{'t_timestamp'} = strftime("%Y-%m-%d %H:%M:%S", CORE::localtime($prefix_vars{'t_epoch'}));
+                                       if ($prefix_vars{'t_epoch'} =~ /^\d{10}(\.\d{3})$/) {
+                                               $prefix_vars{'t_timestamp'} .= $1;
+                                       }
                                }
                        }
                        next if (!$prefix_vars{'t_timestamp'});
@@ -11856,6 +11866,7 @@ sub build_log_line_prefix_regex
                '%r' => [('t_hostport',     '([a-zA-Z0-9\-\.]+|\[local\]|\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}|[0-9a-fA-F:]+)?[\(\d\)]*')],     # remote host and port
                '%h' => [('t_client',       '([a-zA-Z0-9\-\.]+|\[local\]|\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}|[0-9a-fA-F:]+)?')],              # remote host
                '%p' => [('t_pid',          '(\d+)')],                                                        # process ID
+               '%n' => [('t_epoch',    '(\d{10}\.\d{3})')],      # timestamp as Unix epoch
                '%t' => [('t_timestamp',    '(\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2})(?: [A-Z\+\-\d]{3,6})?')],      # timestamp without milliseconds
                '%m' => [('t_mtimestamp',   '(\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2})\.\d+(?: [A-Z\+\-\d]{3,6})?')], # timestamp with milliseconds
                '%l' => [('t_session_line', '(\d+)')],                                                        # session line number