]> granicus.if.org Git - postgresql/commitdiff
Add log_line_prefix option 'n' for Unix epoch.
authorJeff Davis <jdavis@postgresql.org>
Mon, 7 Sep 2015 20:46:31 +0000 (13:46 -0700)
committerJeff Davis <jdavis@postgresql.org>
Mon, 7 Sep 2015 20:46:31 +0000 (13:46 -0700)
Prints time as Unix epoch with milliseconds.

Tomas Vondra, reviewed by Fabien Coelho.

doc/src/sgml/config.sgml
src/backend/utils/error/elog.c
src/backend/utils/misc/postgresql.conf.sample

index e3dc23bf1303ccf6b5499e433b136aca955bb720..3ced3997309f87674a26c4b387628bf9c3647bf6 100644 (file)
@@ -4629,6 +4629,11 @@ local0.*    /var/log/postgresql
              <entry>Time stamp with milliseconds</entry>
              <entry>no</entry>
             </row>
+            <row>
+             <entry><literal>%n</literal></entry>
+             <entry>Time stamp with milliseconds (as a Unix epoch)</entry>
+             <entry>no</entry>
+            </row>
             <row>
              <entry><literal>%i</literal></entry>
              <entry>Command tag: type of session's current command</entry>
index 088c714821bde8e2e655d9b12d1e14c99fbc5aa9..9114c55b66b4392f589bd31284748e8955eef4e7 100644 (file)
@@ -2438,6 +2438,20 @@ log_line_prefix(StringInfo buf, ErrorData *edata)
                                                appendStringInfoString(buf, strfbuf);
                                }
                                break;
+                       case 'n':
+                               {
+                                       struct  timeval tv;
+                                       char    strfbuf[128];
+
+                                       gettimeofday(&tv, NULL);
+                                       sprintf(strfbuf, "%ld.%03d", tv.tv_sec, (int)(tv.tv_usec / 1000));
+
+                                       if (padding != 0)
+                                               appendStringInfo(buf, "%*s", padding, strfbuf);
+                                       else
+                                               appendStringInfoString(buf, strfbuf);
+                               }
+                               break;
                        case 's':
                                if (formatted_start_time[0] == '\0')
                                        setup_formatted_start_time();
index 695a88fe7d1bbf21e7485320272d1e7d74810163..c33e5856197bae3b2cbbb32703df0d539687b59a 100644 (file)
                                        #   %p = process ID
                                        #   %t = timestamp without milliseconds
                                        #   %m = timestamp with milliseconds
+                                       #   %n = timestamp with milliseconds (as a Unix epoch)
                                        #   %i = command tag
                                        #   %e = SQL state
                                        #   %c = session ID