Skip to content

Commit 3d5282c

Browse files
committed
Emit a log message if output is about to be redirected away from stderr.
We've seen multiple cases of people looking at the postmaster's original stderr output to try to diagnose problems, not realizing/remembering that their logging configuration is set up to send log messages somewhere else. This seems particularly likely to happen in prepackaged distributions, since many packagers patch the code to change the factory-standard logging configuration to something more in line with their platform conventions. In hopes of reducing confusion, emit a LOG message about this at the point in startup where we are about to switch log output away from the original stderr, providing a pointer to where to look instead. This message will appear as the last thing in the original stderr output. (We might later also try to emit such link messages when logging parameters are changed on-the-fly; but that case seems to be both noticeably harder to do nicely, and much less frequently a problem in practice.) Per discussion, back-patch to 9.3 but not further.
1 parent b52cd9d commit 3d5282c

File tree

5 files changed

+27
-5
lines changed

5 files changed

+27
-5
lines changed

src/backend/postmaster/postmaster.c

+10
Original file line numberDiff line numberDiff line change
@@ -1164,7 +1164,17 @@ PostmasterMain(int argc, char *argv[])
11641164
* Log_destination permits. We don't do this until the postmaster is
11651165
* fully launched, since startup failures may as well be reported to
11661166
* stderr.
1167+
*
1168+
* If we are in fact disabling logging to stderr, first emit a log message
1169+
* saying so, to provide a breadcrumb trail for users who may not remember
1170+
* that their logging is configured to go somewhere else.
11671171
*/
1172+
if (!(Log_destination & LOG_DESTINATION_STDERR))
1173+
ereport(LOG,
1174+
(errmsg("ending log output to stderr"),
1175+
errhint("Future log output will go to log destination \"%s\".",
1176+
Log_destination_string)));
1177+
11681178
whereToSendOutput = DestNone;
11691179

11701180
/*

src/backend/postmaster/syslogger.c

+14-2
Original file line numberDiff line numberDiff line change
@@ -634,6 +634,20 @@ SysLogger_Start(void)
634634
/* now we redirect stderr, if not done already */
635635
if (!redirection_done)
636636
{
637+
#ifdef WIN32
638+
int fd;
639+
#endif
640+
641+
/*
642+
* Leave a breadcrumb trail when redirecting, in case the user
643+
* forgets that redirection is active and looks only at the
644+
* original stderr target file.
645+
*/
646+
ereport(LOG,
647+
(errmsg("redirecting log output to logging collector process"),
648+
errhint("Future log output will appear in directory \"%s\".",
649+
Log_directory)));
650+
637651
#ifndef WIN32
638652
fflush(stdout);
639653
if (dup2(syslogPipe[1], fileno(stdout)) < 0)
@@ -649,8 +663,6 @@ SysLogger_Start(void)
649663
close(syslogPipe[1]);
650664
syslogPipe[1] = -1;
651665
#else
652-
int fd;
653-
654666
/*
655667
* open the pipe in binary mode and make sure stderr is binary
656668
* after it's been dup'ed into, to avoid disturbing the pipe

src/backend/utils/error/elog.c

+1
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ emit_log_hook_type emit_log_hook = NULL;
109109
int Log_error_verbosity = PGERROR_VERBOSE;
110110
char *Log_line_prefix = NULL; /* format for extra log line info */
111111
int Log_destination = LOG_DESTINATION_STDERR;
112+
char *Log_destination_string = NULL;
112113

113114
#ifdef HAVE_SYSLOG
114115

src/backend/utils/misc/guc.c

+1-3
Original file line numberDiff line numberDiff line change
@@ -444,8 +444,6 @@ int tcp_keepalives_count;
444444
* cases provide the value for SHOW to display. The real state is elsewhere
445445
* and is kept in sync by assign_hooks.
446446
*/
447-
static char *log_destination_string;
448-
449447
static char *syslog_ident_str;
450448
static bool phony_autocommit;
451449
static bool session_auth_is_superuser;
@@ -2871,7 +2869,7 @@ static struct config_string ConfigureNamesString[] =
28712869
"depending on the platform."),
28722870
GUC_LIST_INPUT
28732871
},
2874-
&log_destination_string,
2872+
&Log_destination_string,
28752873
"stderr",
28762874
check_log_destination, assign_log_destination, NULL
28772875
},

src/include/utils/elog.h

+1
Original file line numberDiff line numberDiff line change
@@ -428,6 +428,7 @@ typedef enum
428428
extern int Log_error_verbosity;
429429
extern char *Log_line_prefix;
430430
extern int Log_destination;
431+
extern char *Log_destination_string;
431432

432433
/* Log destination bitmap */
433434
#define LOG_DESTINATION_STDERR 1

0 commit comments

Comments
 (0)