*** a/src/backend/utils/error/elog.c
--- b/src/backend/utils/error/elog.c
***************
*** 136,141 **** static int	errordata_stack_depth = -1; /* index of topmost active frame */
--- 136,143 ----
  
  static int	recursion_depth = 0;	/* to detect actual recursion */
  
+ emit_log_hook_type	emit_log_hook = NULL;	/* hook for log interception */
+ 
  /* buffers for formatted timestamps that might be used by both
   * log_line_prefix and csv logs.
   */
***************
*** 1276,1281 **** EmitErrorReport(void)
--- 1278,1286 ----
  	CHECK_STACK_DEPTH();
  	oldcontext = MemoryContextSwitchTo(ErrorContext);
  
+ 	if (emit_log_hook)
+ 		emit_log_hook(edata);
+ 
  	/* Send to server log, if enabled */
  	if (edata->output_to_server)
  		send_message_to_server_log(edata);
*** a/src/include/utils/elog.h
--- b/src/include/utils/elog.h
***************
*** 327,332 **** typedef struct ErrorData
--- 327,334 ----
  	int			saved_errno;	/* errno at entry */
  } ErrorData;
  
+ typedef void (*emit_log_hook_type)(ErrorData *edata);
+ 
  extern void EmitErrorReport(void);
  extern ErrorData *CopyErrorData(void);
  extern void FreeErrorData(ErrorData *edata);
***************
*** 347,352 **** typedef enum
--- 349,355 ----
  extern int	Log_error_verbosity;
  extern char *Log_line_prefix;
  extern int	Log_destination;
+ extern emit_log_hook_type	emit_log_hook;
  
  /* Log destination bitmap */
  #define LOG_DESTINATION_STDERR	 1
