Skip to content

Commit f828654

Browse files
committed
Add log_line_prefix option 'n' for Unix epoch.
Prints time as Unix epoch with milliseconds. Tomas Vondra, reviewed by Fabien Coelho.
1 parent 37239ef commit f828654

File tree

3 files changed

+20
-0
lines changed

3 files changed

+20
-0
lines changed

doc/src/sgml/config.sgml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4629,6 +4629,11 @@ local0.* /var/log/postgresql
46294629
<entry>Time stamp with milliseconds</entry>
46304630
<entry>no</entry>
46314631
</row>
4632+
<row>
4633+
<entry><literal>%n</literal></entry>
4634+
<entry>Time stamp with milliseconds (as a Unix epoch)</entry>
4635+
<entry>no</entry>
4636+
</row>
46324637
<row>
46334638
<entry><literal>%i</literal></entry>
46344639
<entry>Command tag: type of session's current command</entry>

src/backend/utils/error/elog.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2438,6 +2438,20 @@ log_line_prefix(StringInfo buf, ErrorData *edata)
24382438
appendStringInfoString(buf, strfbuf);
24392439
}
24402440
break;
2441+
case 'n':
2442+
{
2443+
struct timeval tv;
2444+
char strfbuf[128];
2445+
2446+
gettimeofday(&tv, NULL);
2447+
sprintf(strfbuf, "%ld.%03d", tv.tv_sec, (int)(tv.tv_usec / 1000));
2448+
2449+
if (padding != 0)
2450+
appendStringInfo(buf, "%*s", padding, strfbuf);
2451+
else
2452+
appendStringInfoString(buf, strfbuf);
2453+
}
2454+
break;
24412455
case 's':
24422456
if (formatted_start_time[0] == '\0')
24432457
setup_formatted_start_time();

src/backend/utils/misc/postgresql.conf.sample

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -425,6 +425,7 @@
425425
# %p = process ID
426426
# %t = timestamp without milliseconds
427427
# %m = timestamp with milliseconds
428+
# %n = timestamp with milliseconds (as a Unix epoch)
428429
# %i = command tag
429430
# %e = SQL state
430431
# %c = session ID

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy