Introduce a LOG_SERVER_ONLY ereport level, which is never sent to client.
authorTom Lane <[email protected]>
Mon, 4 Apr 2016 16:32:42 +0000 (12:32 -0400)
committerTom Lane <[email protected]>
Mon, 4 Apr 2016 16:32:42 +0000 (12:32 -0400)
This elevel is useful for logging audit messages and similar information
that should not be passed to the client.  It's equivalent to LOG in terms
of decisions about logging priority in the postmaster log, but messages
with this elevel will never be sent to the client.

In the current implementation, it's just an alias for the longstanding
COMMERROR elevel (or more accurately, we've made COMMERROR an alias for
this).  At some point it might be interesting to allow a LOG_ONLY flag to
be attached to any elevel, but that would be considerably more complicated,
and it's not clear there's enough use-cases to justify the extra work.
For now, let's just take the easy 90% solution.

David Steele, reviewed by Fabien Coelho, Petr JelĂ­nek, and myself

src/backend/utils/error/elog.c
src/include/utils/elog.h

index 8e006097a64c658f0c0115967dad78e2605695f6..740f089ccdb9887587b148673b044225a7183aaf 100644 (file)
@@ -293,7 +293,7 @@ errstart(int elevel, const char *filename, int lineno,
    output_to_server = is_log_level_output(elevel, log_min_messages);
 
    /* Determine whether message is enabled for client output */
-   if (whereToSendOutput == DestRemote && elevel != COMMERROR)
+   if (whereToSendOutput == DestRemote && elevel != LOG_SERVER_ONLY)
    {
        /*
         * client_min_messages is honored only after we complete the
@@ -2086,7 +2086,7 @@ write_eventlog(int level, const char *line, int len)
        case DEBUG2:
        case DEBUG1:
        case LOG:
-       case COMMERROR:
+       case LOG_SERVER_ONLY:
        case INFO:
        case NOTICE:
            eventlevel = EVENTLOG_INFORMATION_TYPE;
@@ -2965,7 +2965,7 @@ send_message_to_server_log(ErrorData *edata)
                syslog_level = LOG_DEBUG;
                break;
            case LOG:
-           case COMMERROR:
+           case LOG_SERVER_ONLY:
            case INFO:
                syslog_level = LOG_INFO;
                break;
@@ -3595,7 +3595,7 @@ error_severity(int elevel)
            prefix = _("DEBUG");
            break;
        case LOG:
-       case COMMERROR:
+       case LOG_SERVER_ONLY:
            prefix = _("LOG");
            break;
        case INFO:
@@ -3699,7 +3699,7 @@ write_stderr(const char *fmt,...)
 static bool
 is_log_level_output(int elevel, int log_min_level)
 {
-   if (elevel == LOG || elevel == COMMERROR)
+   if (elevel == LOG || elevel == LOG_SERVER_ONLY)
    {
        if (log_min_level == LOG || log_min_level <= ERROR)
            return true;
index 901651ff5e9aa7ba25d2bd0cd4fd1a7af5613764..7471dadd4b662b8ac6729d42d992ca7da283bfe9 100644 (file)
 #define DEBUG1     14          /* used by GUC debug_* variables */
 #define LOG            15          /* Server operational messages; sent only to
                                 * server log by default. */
-#define COMMERROR  16          /* Client communication problems; same as LOG
-                                * for server reporting, but never sent to
-                                * client. */
+#define LOG_SERVER_ONLY 16     /* Same as LOG for server reporting, but never
+                                * sent to client. */
+#define COMMERROR  LOG_SERVER_ONLY     /* Client communication problems; same
+                                        * as LOG for server reporting, but
+                                        * never sent to client. */
 #define INFO       17          /* Messages specifically requested by user (eg
                                 * VACUUM VERBOSE output); always sent to
                                 * client regardless of client_min_messages,
@@ -354,7 +356,7 @@ typedef struct ErrorData
    char       *detail_log;     /* detail error message for server log only */
    char       *hint;           /* hint message */
    char       *context;        /* context message */
-   const char *message_id;     /* message id of .message (original English text) */
+   const char *message_id;     /* primary message's id (original string) */
    char       *schema_name;    /* name of schema */
    char       *table_name;     /* name of table */
    char       *column_name;    /* name of column */