aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeff Davis <jdavis@postgresql.org>2015-09-07 13:46:31 -0700
committerJeff Davis <jdavis@postgresql.org>2015-09-07 13:46:31 -0700
commitf828654e1097bdbb40fedebd9ac1ea045b183e15 (patch)
tree3a2ab2496b3aac2c5c9f98b96ca50b106a2d4223
parent37239ef8c9fa72e0f73a307cc413a03a743878d3 (diff)
downloadpostgresql-f828654e1097bdbb40fedebd9ac1ea045b183e15.tar.gz
postgresql-f828654e1097bdbb40fedebd9ac1ea045b183e15.zip
Add log_line_prefix option 'n' for Unix epoch.
Prints time as Unix epoch with milliseconds. Tomas Vondra, reviewed by Fabien Coelho.
-rw-r--r--doc/src/sgml/config.sgml5
-rw-r--r--src/backend/utils/error/elog.c14
-rw-r--r--src/backend/utils/misc/postgresql.conf.sample1
3 files changed, 20 insertions, 0 deletions
diff --git a/doc/src/sgml/config.sgml b/doc/src/sgml/config.sgml
index e3dc23bf130..3ced3997309 100644
--- a/doc/src/sgml/config.sgml
+++ b/doc/src/sgml/config.sgml
@@ -4630,6 +4630,11 @@ local0.* /var/log/postgresql
<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>
<entry>yes</entry>
diff --git a/src/backend/utils/error/elog.c b/src/backend/utils/error/elog.c
index 088c714821b..9114c55b66b 100644
--- a/src/backend/utils/error/elog.c
+++ b/src/backend/utils/error/elog.c
@@ -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();
diff --git a/src/backend/utils/misc/postgresql.conf.sample b/src/backend/utils/misc/postgresql.conf.sample
index 695a88fe7d1..c33e5856197 100644
--- a/src/backend/utils/misc/postgresql.conf.sample
+++ b/src/backend/utils/misc/postgresql.conf.sample
@@ -425,6 +425,7 @@
# %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