summaryrefslogtreecommitdiff
path: root/src/backend/utils/error/elog.c
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2007-08-04 01:26:54 +0000
committerTom Lane <tgl@sss.pgh.pa.us>2007-08-04 01:26:54 +0000
commitbdd6b62245fe7b5f25c4fec509b80ec930b6deff (patch)
tree91af2ffde788fdd2855b0dfb1c18e2bbb5aa50a1 /src/backend/utils/error/elog.c
parent73852bd520c219051431a74ee511c4f29dd4baf3 (diff)
Switch over to using the src/timezone functions for formatting timestamps
displayed in the postmaster log. This avoids Windows-specific problems with localized time zone names that are in the wrong encoding, and generally seems like a good idea to forestall other potential platform-dependent issues. To preserve the existing behavior that all backends will log in the same time zone, create a new GUC variable log_timezone that can only be changed on a system-wide basis, and reference log-related calculations to that zone instead of the TimeZone variable. This fixes the issue reported by Hiroshi Saito that timestamps printed by xlog.c startup could be improperly localized on Windows. We still need a simpler patch for that problem in the back branches, however.
Diffstat (limited to 'src/backend/utils/error/elog.c')
-rw-r--r--src/backend/utils/error/elog.c56
1 files changed, 16 insertions, 40 deletions
diff --git a/src/backend/utils/error/elog.c b/src/backend/utils/error/elog.c
index 78993a24ebe..d51dd0bf1af 100644
--- a/src/backend/utils/error/elog.c
+++ b/src/backend/utils/error/elog.c
@@ -42,7 +42,7 @@
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/utils/error/elog.c,v 1.191 2007/08/02 23:39:44 adunstan Exp $
+ * $PostgreSQL: pgsql/src/backend/utils/error/elog.c,v 1.192 2007/08/04 01:26:54 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -1495,33 +1495,18 @@ log_line_prefix(StringInfo buf)
break;
case 'm':
{
- /*
- * Note: for %m, %t, and %s we deliberately use the C
- * library's strftime/localtime, and not the equivalent
- * functions from src/timezone. This ensures that all
- * backends will report log entries in the same timezone,
- * namely whatever C-library setting they inherit from the
- * postmaster. If we used src/timezone then local
- * settings of the TimeZone GUC variable would confuse the
- * log.
- */
- time_t stamp_time;
+ struct timeval tv;
+ pg_time_t stamp_time;
char strfbuf[128],
msbuf[8];
- struct timeval tv;
gettimeofday(&tv, NULL);
- stamp_time = tv.tv_sec;
+ stamp_time = (pg_time_t) tv.tv_sec;
- strftime(strfbuf, sizeof(strfbuf),
- /* leave room for milliseconds... */
- /* Win32 timezone names are too long so don't print them */
-#ifndef WIN32
- "%Y-%m-%d %H:%M:%S %Z",
-#else
- "%Y-%m-%d %H:%M:%S ",
-#endif
- localtime(&stamp_time));
+ pg_strftime(strfbuf, sizeof(strfbuf),
+ /* leave room for milliseconds... */
+ "%Y-%m-%d %H:%M:%S %Z",
+ pg_localtime(&stamp_time, log_timezone));
/* 'paste' milliseconds into place... */
sprintf(msbuf, ".%03d", (int) (tv.tv_usec / 1000));
@@ -1532,32 +1517,23 @@ log_line_prefix(StringInfo buf)
break;
case 't':
{
- time_t stamp_time = time(NULL);
+ pg_time_t stamp_time = (pg_time_t) time(NULL);
char strfbuf[128];
- strftime(strfbuf, sizeof(strfbuf),
- /* Win32 timezone names are too long so don't print them */
-#ifndef WIN32
- "%Y-%m-%d %H:%M:%S %Z",
-#else
- "%Y-%m-%d %H:%M:%S",
-#endif
- localtime(&stamp_time));
+ pg_strftime(strfbuf, sizeof(strfbuf),
+ "%Y-%m-%d %H:%M:%S %Z",
+ pg_localtime(&stamp_time, log_timezone));
appendStringInfoString(buf, strfbuf);
}
break;
case 's':
{
+ pg_time_t stamp_time = (pg_time_t) MyStartTime;
char strfbuf[128];
- strftime(strfbuf, sizeof(strfbuf),
- /* Win32 timezone names are too long so don't print them */
-#ifndef WIN32
- "%Y-%m-%d %H:%M:%S %Z",
-#else
- "%Y-%m-%d %H:%M:%S",
-#endif
- localtime(&MyStartTime));
+ pg_strftime(strfbuf, sizeof(strfbuf),
+ "%Y-%m-%d %H:%M:%S %Z",
+ pg_localtime(&stamp_time, log_timezone));
appendStringInfoString(buf, strfbuf);
}
break;