Standardize output buffer size and display format for strftime;

followup to complaint from Korean User's Group.
This commit is contained in:
Tom Lane 2004-03-22 15:34:22 +00:00
parent 682a6bd5eb
commit d81cd7032e
4 changed files with 14 additions and 15 deletions

View File

@ -5,9 +5,8 @@
*/ */
#include "pg_autovacuum.h" #include "pg_autovacuum.h"
#define TIMEBUFF 256
FILE *LOGOUTPUT; FILE *LOGOUTPUT;
char timebuffer[TIMEBUFF];
char logbuffer[4096]; char logbuffer[4096];
void void
@ -15,11 +14,11 @@ log_entry(const char *logentry)
{ {
time_t curtime; time_t curtime;
struct tm *loctime; struct tm *loctime;
char timebuffer[128];
curtime = time(NULL); curtime = time(NULL);
loctime = localtime(&curtime); loctime = localtime(&curtime);
strftime(timebuffer, TIMEBUFF, "%Y-%m-%d %r", loctime); /* cbb - %F is not strftime(timebuffer, sizeof(timebuffer), "%Y-%m-%d %H:%M:%S %Z", loctime);
* always available */
fprintf(LOGOUTPUT, "[%s] %s\n", timebuffer, logentry); fprintf(LOGOUTPUT, "[%s] %s\n", timebuffer, logentry);
} }

View File

@ -10,7 +10,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/utils/adt/nabstime.c,v 1.118 2003/11/29 19:51:58 pgsql Exp $ * $PostgreSQL: pgsql/src/backend/utils/adt/nabstime.c,v 1.119 2004/03/22 15:34:22 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
@ -1724,8 +1724,8 @@ timeofday(PG_FUNCTION_ARGS)
{ {
struct timeval tp; struct timeval tp;
struct timezone tpz; struct timezone tpz;
char templ[100]; char templ[128];
char buf[100]; char buf[128];
text *result; text *result;
int len; int len;

View File

@ -37,7 +37,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/utils/error/elog.c,v 1.130 2004/03/21 22:29:11 tgl Exp $ * $PostgreSQL: pgsql/src/backend/utils/error/elog.c,v 1.131 2004/03/22 15:34:22 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
@ -1187,9 +1187,9 @@ log_line_prefix(StringInfo buf)
case 't': case 't':
{ {
time_t stamp_time = time(NULL); time_t stamp_time = time(NULL);
char strfbuf[32]; char strfbuf[128];
strftime(strfbuf, sizeof(strfbuf), "%Y-%m-%d %H:%M:%S", strftime(strfbuf, sizeof(strfbuf), "%Y-%m-%d %H:%M:%S %Z",
localtime(&stamp_time)); localtime(&stamp_time));
appendStringInfoString(buf, strfbuf); appendStringInfoString(buf, strfbuf);
} }
@ -1198,9 +1198,9 @@ log_line_prefix(StringInfo buf)
if (MyProcPort) if (MyProcPort)
{ {
time_t stamp_time = MyProcPort->session_start.tv_sec; time_t stamp_time = MyProcPort->session_start.tv_sec;
char strfbuf[32]; char strfbuf[128];
strftime(strfbuf, sizeof(strfbuf), "%Y-%m-%d %H:%M:%S", strftime(strfbuf, sizeof(strfbuf), "%Y-%m-%d %H:%M:%S %Z",
localtime(&stamp_time)); localtime(&stamp_time));
appendStringInfoString(buf, strfbuf); appendStringInfoString(buf, strfbuf);
} }

View File

@ -6,7 +6,7 @@
* copyright (c) Oliver Elphick <olly@lfix.co.uk>, 2001; * copyright (c) Oliver Elphick <olly@lfix.co.uk>, 2001;
* licence: BSD * licence: BSD
* *
* $PostgreSQL: pgsql/src/bin/pg_controldata/pg_controldata.c,v 1.13 2004/02/11 22:55:25 tgl Exp $ * $PostgreSQL: pgsql/src/bin/pg_controldata/pg_controldata.c,v 1.14 2004/03/22 15:34:22 tgl Exp $
*/ */
#include "postgres.h" #include "postgres.h"
@ -71,8 +71,8 @@ main(int argc, char *argv[])
char ControlFilePath[MAXPGPATH]; char ControlFilePath[MAXPGPATH];
char *DataDir; char *DataDir;
crc64 crc; crc64 crc;
char pgctime_str[32]; char pgctime_str[128];
char ckpttime_str[32]; char ckpttime_str[128];
char sysident_str[32]; char sysident_str[32];
char *strftime_fmt = "%c"; char *strftime_fmt = "%c";
char *progname; char *progname;