Make ApplyLogRedaction a macro and redefine ereport

pull/3339/head
Marco Slot 2020-01-04 22:54:56 +01:00
parent 06709ee108
commit f1a0582973
5 changed files with 22 additions and 26 deletions

View File

@ -352,17 +352,7 @@ LogRemoteCommand(MultiConnection *connection, const char *command)
return;
}
if (log_min_messages <= NOTICE)
{
/*
* If the message might be written to the server log then we apply
* log redaction to avoid private data from leaking into logs
* (enterprise only).
*/
command = ApplyLogRedaction(command);
}
ereport(NOTICE, (errmsg("issuing %s", command),
ereport(NOTICE, (errmsg("issuing %s", ApplyLogRedaction(command)),
errdetail("on server %s@%s:%d connectionId: %ld", connection->user,
connection->hostname,
connection->port, connection->connectionId)));

View File

@ -489,17 +489,8 @@ LogLocalCommand(const char *command)
return;
}
if (log_min_messages <= NOTICE)
{
/*
* If the message might be written to the server log then we apply
* log redaction to avoid private data from leaking into logs
* (enterprise only).
*/
command = ApplyLogRedaction(command);
}
ereport(NOTICE, (errmsg("executing the command locally: %s", command)));
ereport(NOTICE, (errmsg("executing the command locally: %s",
ApplyLogRedaction(command))));
}

View File

@ -72,7 +72,7 @@ deparse_shard_query_test(PG_FUNCTION_ARGS)
deparse_shard_query(query, InvalidOid, 0, buffer);
elog(INFO, "query: %s", ApplyLogRedaction(buffer->data));
elog(INFO, "query: %s", buffer->data);
}
}

View File

@ -26,10 +26,10 @@ IsLoggableLevel(int logLevel)
/*
* ApplyLogRedaction is only supported in Citus Enterprise
* HashLogMessage is only supported in Citus Enterprise
*/
char *
ApplyLogRedaction(const char *logText)
HashLogMessage(const char *logText)
{
return (char *) logText;
}

View File

@ -9,7 +9,22 @@
#ifndef LOG_UTILS_H
#define LOG_UTILS_H
#include "utils/guc.h"
extern bool IsLoggableLevel(int logLevel);
extern char * ApplyLogRedaction(const char *text);
extern char * HashLogMessage(const char *text);
#define ApplyLogRedaction(text) \
(log_min_messages <= ereport_loglevel ? HashLogMessage(text) : text)
#undef ereport
#define ereport(elevel, rest) \
do { \
int ereport_loglevel = elevel; \
(void) (ereport_loglevel); \
ereport_domain(elevel, TEXTDOMAIN, rest); \
} while (0)
#endif /* LOG_UTILS_H */