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

Commit 2a217c3

Browse files
committed
Coordinate emit_log_hook and all log destinations to share the same timeval
This would cause the timestamp values used by emit_log_hook and all the other log destinations to differ, because the timestamps are reset before sending the logs to the server and after calling the hook. This change matters for emit_log_hook when generating log information with 'n' or 'm' in log_line_prefix through log_status_format(), or when doing direct calls to get_formatted_log_time() like in the JSON or CSV log formats. While on it, this commit fixes a couple of comments related to the formatted timestamps where the JSON was not mentioned. Oversight in dc68668, that I have noticed while reviewing this patch. Author: Kambam Vinay, Michael Paquier Discussion: https://postgr.es/m/CANiRfmsK36A0i8mnQtzaxhSm3CUCimPwJPp4WQNq53OdSNkgWg@mail.gmail.com
1 parent 44086b0 commit 2a217c3

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

src/backend/utils/error/elog.c

+11-6
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ static int recursion_depth = 0; /* to detect actual recursion */
154154

155155
/*
156156
* Saved timeval and buffers for formatted timestamps that might be used by
157-
* both log_line_prefix and csv logs.
157+
* log_line_prefix, csv logs and JSON logs.
158158
*/
159159
static struct timeval saved_timeval;
160160
static bool saved_timeval_set = false;
@@ -1678,6 +1678,14 @@ EmitErrorReport(void)
16781678
CHECK_STACK_DEPTH();
16791679
oldcontext = MemoryContextSwitchTo(edata->assoc_context);
16801680

1681+
/*
1682+
* Reset the formatted timestamp fields before emitting any logs. This
1683+
* includes all the log destinations and emit_log_hook, as the latter
1684+
* could use log_line_prefix or the formatted timestamps.
1685+
*/
1686+
saved_timeval_set = false;
1687+
formatted_log_time[0] = '\0';
1688+
16811689
/*
16821690
* Call hook before sending message to log. The hook function is allowed
16831691
* to turn off edata->output_to_server, so we must recheck that afterward.
@@ -2632,7 +2640,7 @@ get_formatted_log_time(void)
26322640
/*
26332641
* Note: we expect that guc.c will ensure that log_timezone is set up (at
26342642
* least with a minimal GMT value) before Log_line_prefix can become
2635-
* nonempty or CSV mode can be selected.
2643+
* nonempty or CSV/JSON mode can be selected.
26362644
*/
26372645
pg_strftime(formatted_log_time, FORMATTED_TS_LEN,
26382646
/* leave room for milliseconds... */
@@ -2673,7 +2681,7 @@ get_formatted_start_time(void)
26732681
/*
26742682
* Note: we expect that guc.c will ensure that log_timezone is set up (at
26752683
* least with a minimal GMT value) before Log_line_prefix can become
2676-
* nonempty or CSV mode can be selected.
2684+
* nonempty or CSV/JSON mode can be selected.
26772685
*/
26782686
pg_strftime(formatted_start_time, FORMATTED_TS_LEN,
26792687
"%Y-%m-%d %H:%M:%S %Z",
@@ -3151,9 +3159,6 @@ send_message_to_server_log(ErrorData *edata)
31513159

31523160
initStringInfo(&buf);
31533161

3154-
saved_timeval_set = false;
3155-
formatted_log_time[0] = '\0';
3156-
31573162
log_line_prefix(&buf, edata);
31583163
appendStringInfo(&buf, "%s: ", _(error_severity(edata->elevel)));
31593164

0 commit comments

Comments
 (0)