pgsql: Refactor fallback to stderr for csvlog to handle better WIN32 se

From: Michael Paquier <michael(at)paquier(dot)xyz>
To: pgsql-committers(at)lists(dot)postgresql(dot)org
Subject: pgsql: Refactor fallback to stderr for csvlog to handle better WIN32 se
Date: 2021-10-08 02:12:12
Message-ID: E1mYfMq-0000aV-JJ@gemulon.postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-committers

Refactor fallback to stderr for csvlog to handle better WIN32 service case

send_message_to_server_log() would force a redirection of a log entry to
stderr in some cases for csvlog, like the syslogger not being available
yet. If this happens, csvlog would fall back to stderr to log
some information rather than nothing. The code was organized so as
stderr is done before csvlog, with csvlog checking that stderr did not
happen yet with a reversed condition. With this code organization, it
could be possible to lose some messages if running Postgres as a service
on WIN32, as there is no usable stderr, and the handling of the
StringInfoData holding the message for stderr was rather confusing
because of that.

This commit moves the csvlog handling to be before stderr, as as we are
able to track down if it is necessary to log something to stderr. The
reduces the handling of stderr to be in a single code path, adding a
fallback to event logs for a WIN32 service. This also simplifies the
way we handle the StringInfoData for stderr, making easier the
integration of new file-based log destinations. I got to play with
services and event logs on Windows while checking this change.

Reviewed-by: Chris Bandy
Discussion: https://postgr.es/m/YV0vwBovEKf1WXkl@paquier.xyz

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/8b76f89c37973082b3d64f5a27937efcca9d65f6

Modified Files
--------------
src/backend/utils/error/elog.c | 54 +++++++++++++++++++-----------------------
1 file changed, 24 insertions(+), 30 deletions(-)

Browse pgsql-committers by date

  From Date Subject
Next Message Noah Misch 2021-10-08 02:56:59 Re: pgsql: Adjust configure to insist on Perl version >= 5.8.3.
Previous Message Alvaro Herrera 2021-10-07 22:39:17 Re: pgsql: Adjust configure to insist on Perl version >= 5.8.3.