summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTomas Vondra2017-11-12 11:01:53 +0000
committerTomas Vondra2017-11-12 11:01:53 +0000
commite3b5d21fa766fb5c480cddff065635a9ece6cddf (patch)
tree5949ec849735761fa18996e4aaedb2f52c6b92a7
parent3d19f5b035714899820e4cfffca3944bfadc20af (diff)
Use local variable to format timestamp in GTM log line prefix
When formatting log line prefix in GTM, we can't use global variable, because multiple threads may scribble over the same value. This is why the timestamp was missing in some log lines - one thread did the strftime(), but before it used the value another thread truncated the string (which is the first step in formatting a log line). So instead use a local (not shared by threads) variable, and pass it to setup_formatted_log_time() explicitly.
-rw-r--r--src/gtm/common/elog.c11
1 files changed, 5 insertions, 6 deletions
diff --git a/src/gtm/common/elog.c b/src/gtm/common/elog.c
index 9388130a46..4bda0c103c 100644
--- a/src/gtm/common/elog.c
+++ b/src/gtm/common/elog.c
@@ -66,15 +66,14 @@ char *Log_line_prefix = "%l:%p:%m -"; /* format for extra log line info */
#define FORMATTED_TS_LEN 128
static char formatted_start_time[FORMATTED_TS_LEN];
-static char formatted_log_time[FORMATTED_TS_LEN];
static void log_line_prefix(StringInfo buf);
-static void setup_formatted_log_time(void);
+static void setup_formatted_log_time(char formatted_log_time[FORMATTED_TS_LEN]);
/*
* setup formatted_log_time, for consistent times between CSV and regular logs
*/
static void
-setup_formatted_log_time(void)
+setup_formatted_log_time(char formatted_log_time[FORMATTED_TS_LEN])
{
struct timeval tv;
time_t stamp_time;
@@ -101,6 +100,7 @@ log_line_prefix(StringInfo buf)
{
/* static counter for line numbers */
static long log_line_number = 0;
+ static char formatted_log_time[FORMATTED_TS_LEN];
/* has counter been reset in current process? */
static int log_my_pid = 0;
@@ -150,7 +150,8 @@ log_line_prefix(StringInfo buf)
appendStringInfo(buf, "%ld", log_line_number);
break;
case 'm':
- setup_formatted_log_time();
+ formatted_log_time[0] = '\0';
+ setup_formatted_log_time(formatted_log_time);
appendStringInfoString(buf, formatted_log_time);
break;
default:
@@ -791,8 +792,6 @@ send_message_to_server_log(ErrorData *edata)
initStringInfo(&buf);
- formatted_log_time[0] = '\0';
-
log_line_prefix(&buf);
appendStringInfo(&buf, "%s: ", error_severity(edata->elevel));