Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 6c2ba14

Browse files
committed
This patch against 8.0.0beta1 source adds log_line_prefix options for
millisecond timestamps (%m) and remote host (%h). The milliseconds are useful for QPS measurements. Ed L.
1 parent 7974c35 commit 6c2ba14

File tree

3 files changed

+45
-3
lines changed

3 files changed

+45
-3
lines changed

doc/src/sgml/runtime.sgml

+11-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!--
2-
$PostgreSQL: pgsql/doc/src/sgml/runtime.sgml,v 1.322 2005/06/04 20:42:41 momjian Exp $
2+
$PostgreSQL: pgsql/doc/src/sgml/runtime.sgml,v 1.323 2005/06/09 22:29:52 momjian Exp $
33
-->
44

55
<chapter Id="runtime">
@@ -2829,6 +2829,11 @@ archive_command = 'copy "%p" /mnt/server/archivedir/"%f"' # Windows
28292829
<entry>Remote host name or IP address, and remote port</entry>
28302830
<entry>yes</entry>
28312831
</row>
2832+
<row>
2833+
<entry><literal>%h</literal></entry>
2834+
<entry>Remote Hostname or IP address</entry>
2835+
<entry>yes</entry>
2836+
</row>
28322837
<row>
28332838
<entry><literal>%p</literal></entry>
28342839
<entry>Process ID</entry>
@@ -2839,6 +2844,11 @@ archive_command = 'copy "%p" /mnt/server/archivedir/"%f"' # Windows
28392844
<entry>Time stamp</entry>
28402845
<entry>no</entry>
28412846
</row>
2847+
<row>
2848+
<entry><literal>%m</literal></entry>
2849+
<entry>Timestamp with milliseconds</entry>
2850+
<entry>no</entry>
2851+
</row>
28422852
<row>
28432853
<entry><literal>%i</literal></entry>
28442854
<entry>Command tag: This is the command that generated the log line.</entry>

src/backend/utils/error/elog.c

+32-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
*
4343
*
4444
* IDENTIFICATION
45-
* $PostgreSQL: pgsql/src/backend/utils/error/elog.c,v 1.158 2005/03/12 01:54:44 tgl Exp $
45+
* $PostgreSQL: pgsql/src/backend/utils/error/elog.c,v 1.159 2005/06/09 22:29:52 momjian Exp $
4646
*
4747
*-------------------------------------------------------------------------
4848
*/
@@ -1375,6 +1375,33 @@ log_line_prefix(StringInfo buf)
13751375
case 'l':
13761376
appendStringInfo(buf, "%ld", log_line_number);
13771377
break;
1378+
case 'm':
1379+
{
1380+
time_t stamp_time;
1381+
char strfbuf[128], msbuf[5];
1382+
struct timeval tv;
1383+
1384+
gettimeofday(&tv, NULL);
1385+
stamp_time = tv.tv_sec;
1386+
1387+
strftime(strfbuf, sizeof(strfbuf),
1388+
/* leave room for milliseconds... */
1389+
/* Win32 timezone names are too long so don't print them. */
1390+
#ifndef WIN32
1391+
"%Y-%m-%d %H:%M:%S %Z",
1392+
#else
1393+
"%Y-%m-%d %H:%M:%S ",
1394+
#endif
1395+
localtime(&stamp_time));
1396+
1397+
/* 'paste' milliseconds into place... */
1398+
sprintf(msbuf, ".%03d",
1399+
(int)(tv.tv_usec/1000));
1400+
strncpy(strfbuf+19, msbuf, 4);
1401+
1402+
appendStringInfoString(buf, strfbuf);
1403+
}
1404+
break;
13781405
case 't':
13791406
{
13801407
/*
@@ -1426,6 +1453,10 @@ log_line_prefix(StringInfo buf)
14261453
MyProcPort->remote_port);
14271454
}
14281455
break;
1456+
case 'h':
1457+
if (MyProcPort)
1458+
appendStringInfo(buf, "%s", MyProcPort->remote_host);
1459+
break;
14291460
case 'q':
14301461
/* in postmaster and friends, stop if %q is seen */
14311462
/* in a backend, just ignore */

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

+2-1
Original file line numberDiff line numberDiff line change
@@ -241,8 +241,9 @@
241241
#log_duration = false
242242
#log_line_prefix = '' # e.g. '<%u%%%d> '
243243
# %u=user name %d=database name
244-
# %r=remote host and port
244+
# %r=remote host and port %h=remote host
245245
# %p=PID %t=timestamp %i=command tag
246+
# %m=timestamp with milliseconds
246247
# %c=session id %l=session line number
247248
# %s=session start timestamp %x=transaction id
248249
# %q=stop here in non-session processes

0 commit comments

Comments
 (0)