]> granicus.if.org Git - postgresql/commitdiff
Emit a log message if output is about to be redirected away from stderr.
authorTom Lane <tgl@sss.pgh.pa.us>
Tue, 13 Aug 2013 19:24:56 +0000 (15:24 -0400)
committerTom Lane <tgl@sss.pgh.pa.us>
Tue, 13 Aug 2013 19:24:56 +0000 (15:24 -0400)
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.

src/backend/postmaster/postmaster.c
src/backend/postmaster/syslogger.c
src/backend/utils/error/elog.c
src/backend/utils/misc/guc.c
src/include/utils/elog.h

index 554710850862fdc9bd8cc1e302d777a4c28c265a..75f2f82548f4a6d0917f821b77ae440dcb59337c 100644 (file)
@@ -1183,7 +1183,17 @@ PostmasterMain(int argc, char *argv[])
         * Log_destination permits.  We don't do this until the postmaster is
         * fully launched, since startup failures may as well be reported to
         * stderr.
+        *
+        * If we are in fact disabling logging to stderr, first emit a log message
+        * saying so, to provide a breadcrumb trail for users who may not remember
+        * that their logging is configured to go somewhere else.
         */
+       if (!(Log_destination & LOG_DESTINATION_STDERR))
+               ereport(LOG,
+                               (errmsg("ending log output to stderr"),
+                                errhint("Future log output will go to log destination \"%s\".",
+                                                Log_destination_string)));
+
        whereToSendOutput = DestNone;
 
        /*
index e3b6102516285c3051412c8b7b8c3ad8b435fc75..8b00aa525b2f57e308886c35e12a8cc7f9b979b0 100644 (file)
@@ -634,6 +634,20 @@ SysLogger_Start(void)
                        /* now we redirect stderr, if not done already */
                        if (!redirection_done)
                        {
+#ifdef WIN32
+                               int                     fd;
+#endif
+
+                               /*
+                                * Leave a breadcrumb trail when redirecting, in case the user
+                                * forgets that redirection is active and looks only at the
+                                * original stderr target file.
+                                */
+                               ereport(LOG,
+                                               (errmsg("redirecting log output to logging collector process"),
+                                                errhint("Future log output will appear in directory \"%s\".",
+                                                                Log_directory)));
+
 #ifndef WIN32
                                fflush(stdout);
                                if (dup2(syslogPipe[1], fileno(stdout)) < 0)
@@ -649,8 +663,6 @@ SysLogger_Start(void)
                                close(syslogPipe[1]);
                                syslogPipe[1] = -1;
 #else
-                               int                     fd;
-
                                /*
                                 * open the pipe in binary mode and make sure stderr is binary
                                 * after it's been dup'ed into, to avoid disturbing the pipe
index 7f03f419dead8f7f325a8e24a345d23fb1667192..cebfeebad73700fd93ce59c54788c5a136bef131 100644 (file)
@@ -109,6 +109,7 @@ emit_log_hook_type emit_log_hook = NULL;
 int                    Log_error_verbosity = PGERROR_VERBOSE;
 char      *Log_line_prefix = NULL;             /* format for extra log line info */
 int                    Log_destination = LOG_DESTINATION_STDERR;
+char      *Log_destination_string = NULL;
 
 #ifdef HAVE_SYSLOG
 
index b53fdc2be37f3eb2f893eaa35db2c713bb567fe8..a055231cfc0c62acc083d309b6c15145740cb27c 100644 (file)
@@ -442,8 +442,6 @@ int                 tcp_keepalives_count;
  * cases provide the value for SHOW to display.  The real state is elsewhere
  * and is kept in sync by assign_hooks.
  */
-static char *log_destination_string;
-
 static char *syslog_ident_str;
 static bool phony_autocommit;
 static bool session_auth_is_superuser;
@@ -2833,7 +2831,7 @@ static struct config_string ConfigureNamesString[] =
                                                 "depending on the platform."),
                        GUC_LIST_INPUT
                },
-               &log_destination_string,
+               &Log_destination_string,
                "stderr",
                check_log_destination, assign_log_destination, NULL
        },
index 85bd2fdf8a2dbcde7d0a70f3507b8ae1fc917ac5..76f6367840de1537bb285a44b1518dfe56bbc23d 100644 (file)
@@ -423,6 +423,7 @@ typedef enum
 extern int     Log_error_verbosity;
 extern char *Log_line_prefix;
 extern int     Log_destination;
+extern char *Log_destination_string;
 
 /* Log destination bitmap */
 #define LOG_DESTINATION_STDERR  1