diff --git a/doc/src/sgml/func.sgml b/doc/src/sgml/func.sgml index 76f77cb..b2fc4cd 100644 --- a/doc/src/sgml/func.sgml +++ b/doc/src/sgml/func.sgml @@ -17850,6 +17850,15 @@ postgres=# SELECT * FROM pg_xlogfile_name_offset(pg_stop_backup()); Return information about a file. + + + pg_report_log(message text]) + + void + + Write message into log file. + + @@ -17918,6 +17927,18 @@ SELECT (pg_stat_file('filename')).modification; + + pg_report_log + + + pg_report_log is useful to write custom messages + into current log destination and returns void. + Typical usages include: + +SELECT pg_report_log('Message'); + + + diff --git a/src/backend/utils/adt/misc.c b/src/backend/utils/adt/misc.c index c0495d9..6c54f3a 100644 --- a/src/backend/utils/adt/misc.c +++ b/src/backend/utils/adt/misc.c @@ -76,6 +76,23 @@ current_query(PG_FUNCTION_ARGS) } /* + * pg_report_log() + * + * Printing custom log messages in log file. + */ + +Datum +pg_report_log(PG_FUNCTION_ARGS) +{ + + ereport(MESSAGE, + (errmsg("%s", text_to_cstring(PG_GETARG_TEXT_P(0))), + errhidestmt(true))); + + PG_RETURN_VOID(); +} + +/* * Send a signal to another backend. * * The signal is delivered if the user is either a superuser or the same diff --git a/src/backend/utils/error/elog.c b/src/backend/utils/error/elog.c index 088c714..2e8f547 100644 --- a/src/backend/utils/error/elog.c +++ b/src/backend/utils/error/elog.c @@ -302,7 +302,7 @@ errstart(int elevel, const char *filename, int lineno, elevel == INFO); } - /* Skip processing effort if non-error message will not be output */ + /* Skip processing effort if non-error,custom message will not be output */ if (elevel < ERROR && !output_to_server && !output_to_client) return false; @@ -2062,6 +2062,7 @@ write_eventlog(int level, const char *line, int len) case DEBUG3: case DEBUG2: case DEBUG1: + case MESSAGE: case LOG: case COMMERROR: case INFO: @@ -2917,6 +2918,7 @@ send_message_to_server_log(ErrorData *edata) case DEBUG1: syslog_level = LOG_DEBUG; break; + case MESSAGE: case LOG: case COMMERROR: case INFO: @@ -3547,6 +3549,7 @@ error_severity(int elevel) case DEBUG5: prefix = _("DEBUG"); break; + case MESSAGE: case LOG: case COMMERROR: prefix = _("LOG"); @@ -3666,6 +3669,9 @@ is_log_level_output(int elevel, int log_min_level) /* Neither is LOG */ else if (elevel >= log_min_level) return true; + /* If elevel is MESSAGE, then ignore log settings */ + else if (elevel == MESSAGE) + return true; return false; } diff --git a/src/include/catalog/pg_proc.h b/src/include/catalog/pg_proc.h index 6fd1278..62c619a 100644 --- a/src/include/catalog/pg_proc.h +++ b/src/include/catalog/pg_proc.h @@ -5344,6 +5344,11 @@ DESCR("tsm_bernoulli_reset(internal)"); DATA(insert OID = 3346 ( tsm_bernoulli_cost PGNSP PGUID 12 1 0 0 0 f f f f t f v 7 0 2278 "2281 2281 2281 2281 2281 2281 2281" _null_ _null_ _null_ _null_ _null_ tsm_bernoulli_cost _null_ _null_ _null_ )); DESCR("tsm_bernoulli_cost(internal)"); +/* Logging function */ + +DATA(insert OID = 6015 ( pg_report_log PGNSP PGUID 12 1 0 0 0 f f f f t f v 1 0 2278 "1043" _null_ _null_ _null_ _null_ _null_ pg_report_log _null_ _null_ _null_ )); +DESCR("write message to log file"); + /* * Symbolic values for provolatile column: these indicate whether the result * of a function is dependent *only* on the values of its explicit arguments, diff --git a/src/include/utils/builtins.h b/src/include/utils/builtins.h index fcb0bf0..3a2164b 100644 --- a/src/include/utils/builtins.h +++ b/src/include/utils/builtins.h @@ -495,6 +495,7 @@ extern Datum pg_typeof(PG_FUNCTION_ARGS); extern Datum pg_collation_for(PG_FUNCTION_ARGS); extern Datum pg_relation_is_updatable(PG_FUNCTION_ARGS); extern Datum pg_column_is_updatable(PG_FUNCTION_ARGS); +extern Datum pg_report_log(PG_FUNCTION_ARGS); /* oid.c */ extern Datum oidin(PG_FUNCTION_ARGS); diff --git a/src/include/utils/elog.h b/src/include/utils/elog.h index 7684717..3054d3c 100644 --- a/src/include/utils/elog.h +++ b/src/include/utils/elog.h @@ -16,6 +16,9 @@ #include +/* Custom log message */ +#define MESSAGE 9 /* Custom messages to log file*/ + /* Error level codes */ #define DEBUG5 10 /* Debugging messages, in categories of * decreasing detail. */