Skip to content
Snippets Groups Projects
Commit 6f9e3072 authored by Michael Paquier's avatar Michael Paquier
Browse files

jsonlog: improve redirection of first logs messages

Before server parameters are loaded, enforce redirection of log messages
to stderr, using the same method as what syslogger.c and postmaster.c do.
Also avoid duplicate entries to server logs, and be careful about messages
that are too verbose.
parent a49078e4
No related branches found
No related tags found
No related merge requests found
Loading
Loading
@@ -37,6 +37,13 @@ void _PG_fini(void);
/* Hold previous logging hook */
static emit_log_hook_type prev_log_hook = NULL;
 
/*
* Track if redirection to syslogger can happen. This uses the same method
* as postmaster.c and syslogger.c, this flag being updated by the postmaster
* once server parameters are loaded.
*/
extern bool redirection_done;
/* Log timestamp */
#define LOG_TIMESTAMP_LEN 128
static char log_time[LOG_TIMESTAMP_LEN];
Loading
Loading
@@ -210,6 +217,19 @@ write_jsonlog(ErrorData *edata)
StringInfoData buf;
TransactionId txid = GetTopTransactionIdIfAny();
 
/*
* Disable logs to server, we don't want duplicate entries in
* the server.
*/
edata->output_to_server = false;
/*
* Nothing to do if log message has a severity lower than the minimum
* wanted.
*/
if (edata->elevel < log_min_messages)
return;
initStringInfo(&buf);
 
/* Initialize string */
Loading
Loading
@@ -318,14 +338,7 @@ write_jsonlog(ErrorData *edata)
/* Write to stderr, if enabled */
if ((Log_destination & LOG_DESTINATION_STDERR) != 0)
{
/*
* In the case where logging_collector is enabled, the first entries
* generated by the postmaster will include some junk prefix as those
* are unconditionally logged into stderr and the message format uses
* a pipe. There is not much doable for that as this needs a flag that
* only the postmaster and syslogger.c have an access to.
*/
if (Logging_collector && !am_syslogger)
if (Logging_collector && redirection_done && !am_syslogger)
write_pipe_chunks(buf.data, buf.len);
else
write_console(buf.data, buf.len);
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment