Index: src/backend/utils/error/elog.c
===================================================================
RCS file: /cvsroot/pgsql/src/backend/utils/error/elog.c,v
retrieving revision 1.91
diff -c -r1.91 elog.c
*** src/backend/utils/error/elog.c	5 Nov 2001 17:46:30 -0000	1.91
--- src/backend/utils/error/elog.c	25 Feb 2002 06:57:04 -0000
***************
*** 38,43 ****
--- 38,53 ----
  #include "mb/pg_wchar.h"
  #endif
  
+ #define DEFAULT_SERVER_MIN_MESSAGES_STR "LOG"
+ int			server_min_messages;
+ char	   *server_min_messages_str = NULL;
+ const char	server_min_messages_str_default[] = DEFAULT_SERVER_MIN_MESSAGES_STR;
+ 
+ #define DEFAULT_CLIENT_MIN_MESSAGES_STR "INFO"
+ int			client_min_messages;
+ char	   *client_min_messages_str = NULL;
+ const char	client_min_messages_str_default[] = DEFAULT_CLIENT_MIN_MESSAGES_STR;
+ 
  #ifdef ENABLE_SYSLOG
  /*
   * 0 = only stdout/stderr
***************
*** 109,115 ****
  	 * Note that we use malloc() not palloc() because we want to retain
  	 * control if we run out of memory.  palloc() would recursively call
  	 * elog(ERROR), which would be all right except if we are working on a
! 	 * FATAL or REALLYFATAL error.	We'd lose track of the fatal condition
  	 * and report a mere ERROR to outer loop, which would be a Bad Thing.
  	 * So, we substitute an appropriate message in-place, without
  	 * downgrading the level if it's above ERROR.
--- 119,125 ----
  	 * Note that we use malloc() not palloc() because we want to retain
  	 * control if we run out of memory.  palloc() would recursively call
  	 * elog(ERROR), which would be all right except if we are working on a
! 	 * FATAL or PANIC error.	We'd lose track of the fatal condition
  	 * and report a mere ERROR to outer loop, which would be a Bad Thing.
  	 * So, we substitute an appropriate message in-place, without
  	 * downgrading the level if it's above ERROR.
***************
*** 131,136 ****
--- 141,151 ----
  	/* size of the prefix needed for timestamp and pid, if enabled */
  	size_t		timestamp_size;
  
+ 
+ 	/* Check for old elog calls.  Codes were renumbered in 7.3. 2002-02-24 */
+ 	if (lev < DEBUG)
+ 		elog(FATAL, "Pre-7.3 object file made an elog() call.  Recompile.");
+ 
  	/* Save error str before calling any function that might change errno */
  	errorstr = useful_strerror(errno);
  
***************
*** 142,154 ****
  		lev = FATAL;
  
  	/*
! 	 * If we are inside a critical section, all errors become REALLYFATAL
  	 * errors.	See miscadmin.h.
  	 */
  	if (lev == ERROR || lev == FATAL)
  	{
  		if (CritSectionCount > 0)
! 			lev = REALLYFATAL;
  	}
  
  	prefix = elog_message_prefix(lev);
--- 157,169 ----
  		lev = FATAL;
  
  	/*
! 	 * If we are inside a critical section, all errors become PANIC
  	 * errors.	See miscadmin.h.
  	 */
  	if (lev == ERROR || lev == FATAL)
  	{
  		if (CritSectionCount > 0)
! 			lev = PANIC;
  	}
  
  	prefix = elog_message_prefix(lev);
***************
*** 167,178 ****
  	 * vsnprintf won't know what to do with %m).  To keep space
  	 * calculation simple, we only allow one %m.
  	 */
! 	space_needed = timestamp_size + strlen(prefix)
! 		+ strlen(fmt) + strlen(errorstr) + 1;
  
  	if (copy_lineno)
  	{
! 		/* translator: This string will be truncated at 31 characters. */
  		snprintf(copylineno_buf, 32, gettext("copy: line %d, "), copy_lineno);
  		space_needed += strlen(copylineno_buf);
  	}
--- 182,196 ----
  	 * vsnprintf won't know what to do with %m).  To keep space
  	 * calculation simple, we only allow one %m.
  	 */
! 	space_needed = timestamp_size + strlen(prefix) +
! 				   strlen(fmt) + strlen(errorstr) + 1;
  
  	if (copy_lineno)
  	{
! 		/*
! 		 * Prints the failure line of the COPY.  Wow, what a hack!  bjm
! 		 * Translators:  Error message will be truncated at 31 characters.
! 		 */
  		snprintf(copylineno_buf, 32, gettext("copy: line %d, "), copy_lineno);
  		space_needed += strlen(copylineno_buf);
  	}
***************
*** 184,190 ****
  		{
  			/* We're up against it, convert to out-of-memory error */
  			fmt_buf = fmt_fixedbuf;
! 			if (lev != FATAL && lev != REALLYFATAL)
  			{
  				lev = ERROR;
  				prefix = elog_message_prefix(lev);
--- 202,208 ----
  		{
  			/* We're up against it, convert to out-of-memory error */
  			fmt_buf = fmt_fixedbuf;
! 			if (lev != FATAL && lev != PANIC)
  			{
  				lev = ERROR;
  				prefix = elog_message_prefix(lev);
***************
*** 213,219 ****
  	if (copy_lineno)
  	{
  		strcat(fmt_buf, copylineno_buf);
! 		if (lev == ERROR || lev == FATAL || lev == REALLYFATAL)
  			copy_lineno = 0;
  	}
  
--- 231,237 ----
  	if (copy_lineno)
  	{
  		strcat(fmt_buf, copylineno_buf);
! 		if (lev == ERROR || lev == FATAL || lev == PANIC)
  			copy_lineno = 0;
  	}
  
***************
*** 281,287 ****
  		{
  			/* We're up against it, convert to out-of-memory error */
  			msg_buf = msg_fixedbuf;
! 			if (lev != FATAL && lev != REALLYFATAL)
  			{
  				lev = ERROR;
  				prefix = elog_message_prefix(lev);
--- 299,305 ----
  		{
  			/* We're up against it, convert to out-of-memory error */
  			msg_buf = msg_fixedbuf;
! 			if (lev != FATAL && lev != PANIC)
  			{
  				lev = ERROR;
  				prefix = elog_message_prefix(lev);
***************
*** 312,317 ****
--- 330,339 ----
  			case DEBUG:
  				syslog_level = LOG_DEBUG;
  				break;
+ 			case LOG:
+ 			case INFO:
+ 				syslog_level = LOG_INFO;
+ 				break;
  			case NOTICE:
  				syslog_level = LOG_NOTICE;
  				break;
***************
*** 321,327 ****
  			case FATAL:
  				syslog_level = LOG_ERR;
  				break;
! 			case REALLYFATAL:
  			default:
  				syslog_level = LOG_CRIT;
  				break;
--- 343,349 ----
  			case FATAL:
  				syslog_level = LOG_ERR;
  				break;
! 			case PANIC:
  			default:
  				syslog_level = LOG_CRIT;
  				break;
***************
*** 334,344 ****
  	/* syslog doesn't want a trailing newline, but other destinations do */
  	strcat(msg_buf, "\n");
  
! 	/* write to terminal */
! 	if (Use_syslog <= 1 || whereToSendOutput == Debug)
  		write(2, msg_buf, strlen(msg_buf));
  
! 	if (lev > DEBUG && whereToSendOutput == Remote)
  	{
  		/* Send IPC message to the front-end program */
  		MemoryContext oldcxt;
--- 356,371 ----
  	/* syslog doesn't want a trailing newline, but other destinations do */
  	strcat(msg_buf, "\n");
  
! 	/* Write to server logs or server terminal */
! 	if ((lev >= server_min_messages ||
! 		/* INFO/LOG priority are reversed for server.  Handle this */
! 		(lev == LOG && server_min_messages == INFO)) &&
! 		(lev != INFO || server_min_messages != LOG) &&
! 		(Use_syslog <= 1 || whereToSendOutput == Debug))
  		write(2, msg_buf, strlen(msg_buf));
  
! 	/* Should we output to the client too? */
! 	if (lev >= client_min_messages || whereToSendOutput == Remote)
  	{
  		/* Send IPC message to the front-end program */
  		MemoryContext oldcxt;
***************
*** 351,357 ****
  		 */
  		oldcxt = MemoryContextSwitchTo(ErrorContext);
  
! 		if (lev == NOTICE)
  			/* exclude the timestamp from msg sent to frontend */
  			send_notice_to_frontend(msg_buf + timestamp_size);
  		else
--- 378,384 ----
  		 */
  		oldcxt = MemoryContextSwitchTo(ErrorContext);
  
! 		if (lev <= NOTICE)
  			/* exclude the timestamp from msg sent to frontend */
  			send_notice_to_frontend(msg_buf + timestamp_size);
  		else
***************
*** 414,420 ****
  		 * Guard against infinite loop from elog() during error recovery.
  		 */
  		if (InError)
! 			elog(REALLYFATAL, "elog: error during error recovery, giving up!");
  		InError = true;
  
  		/*
--- 441,447 ----
  		 * Guard against infinite loop from elog() during error recovery.
  		 */
  		if (InError)
! 			elog(PANIC, "elog: error during error recovery, giving up!");
  		InError = true;
  
  		/*
***************
*** 423,429 ****
  		siglongjmp(Warn_restart, 1);
  	}
  
! 	if (lev == FATAL || lev == REALLYFATAL)
  	{
  		/*
  		 * Serious crash time. Postmaster will observe nonzero process
--- 450,456 ----
  		siglongjmp(Warn_restart, 1);
  	}
  
! 	if (lev == FATAL || lev == PANIC)
  	{
  		/*
  		 * Serious crash time. Postmaster will observe nonzero process
***************
*** 673,682 ****
  {
  	StringInfoData buf;
  
! 	AssertArg(type == NOTICE || type == ERROR);
  
  	pq_beginmessage(&buf);
! 	pq_sendbyte(&buf, type == NOTICE ? 'N' : 'E');
  	pq_sendstring(&buf, msg);
  	pq_endmessage(&buf);
  
--- 700,709 ----
  {
  	StringInfoData buf;
  
! 	AssertArg(type <= ERROR);
  
  	pq_beginmessage(&buf);
! 	pq_sendbyte(&buf, type != ERROR ? 'N' : 'E'); /* No reason to add INFO */
  	pq_sendstring(&buf, msg);
  	pq_endmessage(&buf);
  
***************
*** 734,739 ****
--- 761,772 ----
  		case DEBUG:
  			prefix = gettext("DEBUG:  ");
  			break;
+ 		case LOG:
+ 			prefix = gettext("LOG:  ");
+ 			break;
+ 		case INFO:
+ 			prefix = gettext("INFO:  ");
+ 			break;
  		case NOTICE:
  			prefix = gettext("NOTICE:  ");
  			break;
***************
*** 741,753 ****
  			prefix = gettext("ERROR:  ");
  			break;
  		case FATAL:
! 			prefix = gettext("FATAL 1:  ");
  			break;
! 		case REALLYFATAL:
! 			prefix = gettext("FATAL 2:  ");
  			break;
  	}
  
  	Assert(prefix != NULL);
  	return prefix;
  }
--- 774,859 ----
  			prefix = gettext("ERROR:  ");
  			break;
  		case FATAL:
! 			prefix = gettext("FATAL:  ");
  			break;
! 		case PANIC:
! 			prefix = gettext("PANIC:  ");
  			break;
  	}
  
  	Assert(prefix != NULL);
  	return prefix;
  }
+ 
+ 
+ /*
+  * GUC support routines
+  */
+ 
+ bool
+ check_server_min_messages(const char *lev)
+ {
+ 	if (strcasecmp(lev, "debug") == 0 ||
+ 		strcasecmp(lev, "log") == 0 ||
+ 		strcasecmp(lev, "info") == 0 ||
+ 		strcasecmp(lev, "notice") == 0 ||
+ 		strcasecmp(lev, "error") == 0 ||
+ 		strcasecmp(lev, "fatal") == 0 ||
+ 		strcasecmp(lev, "panic") == 0)
+ 		return true;
+ 	return false;
+ }
+ 
+ void
+ assign_server_min_messages(const char *lev)
+ {
+ 	if (strcasecmp(lev, "debug") == 0)
+ 		server_min_messages = DEBUG;
+ 	else if (strcasecmp(lev, "log") == 0)
+ 		server_min_messages = LOG;
+ 	else if (strcasecmp(lev, "info") == 0)
+ 		server_min_messages = INFO;
+ 	else if (strcasecmp(lev, "notice") == 0)
+ 		server_min_messages = NOTICE;
+ 	else if (strcasecmp(lev, "error") == 0)
+ 		server_min_messages = ERROR;
+ 	else if (strcasecmp(lev, "fatal") == 0)
+ 		server_min_messages = FATAL;
+ 	else if (strcasecmp(lev, "panic") == 0)
+ 		server_min_messages = PANIC;
+ 	else
+ 		/* Can't get here unless guc.c screwed up */
+ 		elog(ERROR, "bogus server_min_messages %s", lev);
+ }
+ 
+ bool
+ check_client_min_messages(const char *lev)
+ {
+ 	if (strcasecmp(lev, "debug") == 0 ||
+ 		strcasecmp(lev, "log") == 0 ||
+ 		strcasecmp(lev, "info") == 0 ||
+ 		strcasecmp(lev, "notice") == 0 ||
+ 		strcasecmp(lev, "error") == 0)
+ 		return true;
+ 	return false;
+ }
+ 
+ void
+ assign_client_min_messages(const char *lev)
+ {
+ 	if (strcasecmp(lev, "debug") == 0)
+ 		client_min_messages = DEBUG;
+ 	else if (strcasecmp(lev, "log") == 0)
+ 		client_min_messages = LOG;
+ 	else if (strcasecmp(lev, "info") == 0)
+ 		client_min_messages = INFO;
+ 	else if (strcasecmp(lev, "notice") == 0)
+ 		client_min_messages = NOTICE;
+ 	else if (strcasecmp(lev, "error") == 0)
+ 		client_min_messages = ERROR;
+ 	else
+ 		/* Can't get here unless guc.c screwed up */
+ 		elog(ERROR, "bogus client_min_messages %s", lev);
+ }
+ 
+ 
Index: src/backend/utils/hash/dynahash.c
===================================================================
RCS file: /cvsroot/pgsql/src/backend/utils/hash/dynahash.c,v
retrieving revision 1.40
diff -c -r1.40 dynahash.c
*** src/backend/utils/hash/dynahash.c	28 Oct 2001 06:25:54 -0000	1.40
--- src/backend/utils/hash/dynahash.c	25 Feb 2002 06:57:09 -0000
***************
*** 933,939 ****
  	 * systemwide restart.	Otherwise, just shut down this one backend.
  	 */
  	if (hashp->isshared)
! 		elog(STOP, "Hash table '%s' corrupted", hashp->tabname);
  	else
  		elog(FATAL, "Hash table '%s' corrupted", hashp->tabname);
  }
--- 933,939 ----
  	 * systemwide restart.	Otherwise, just shut down this one backend.
  	 */
  	if (hashp->isshared)
! 		elog(PANIC, "Hash table '%s' corrupted", hashp->tabname);
  	else
  		elog(FATAL, "Hash table '%s' corrupted", hashp->tabname);
  }
Index: src/backend/utils/misc/guc.c
===================================================================
RCS file: /cvsroot/pgsql/src/backend/utils/misc/guc.c,v
retrieving revision 1.59
diff -c -r1.59 guc.c
*** src/backend/utils/misc/guc.c	23 Feb 2002 01:31:36 -0000	1.59
--- src/backend/utils/misc/guc.c	25 Feb 2002 06:57:10 -0000
***************
*** 37,42 ****
--- 37,43 ----
  #include "storage/proc.h"
  #include "tcop/tcopprot.h"
  #include "utils/datetime.h"
+ #include "utils/elog.h"
  #include "pgstat.h"
  
  
***************
*** 554,559 ****
--- 555,566 ----
  			ConfigureNamesString[] =
  {
  	{
+ 		"client_min_messages", PGC_USERSET, PGC_S_DEFAULT, &client_min_messages_str,
+ 		client_min_messages_str_default, check_client_min_messages,
+ 		assign_client_min_messages
+ 	},
+ 
+ 	{
  		"default_transaction_isolation", PGC_USERSET, PGC_S_DEFAULT, &default_iso_level_string,
  		"read committed", check_defaultxactisolevel, assign_defaultxactisolevel
  	},
***************
*** 566,571 ****
--- 573,584 ----
  	{
  		"krb_server_keyfile", PGC_POSTMASTER, PGC_S_DEFAULT, &pg_krb_server_keyfile,
  		PG_KRB_SRVTAB, NULL, NULL
+ 	},
+ 
+ 	{
+ 		"server_min_messages", PGC_USERSET, PGC_S_DEFAULT, &server_min_messages_str,
+ 		server_min_messages_str_default, check_server_min_messages,
+ 		assign_server_min_messages
  	},
  
  #ifdef ENABLE_SYSLOG
Index: src/backend/utils/misc/postgresql.conf.sample
===================================================================
RCS file: /cvsroot/pgsql/src/backend/utils/misc/postgresql.conf.sample,v
retrieving revision 1.29
diff -c -r1.29 postgresql.conf.sample
*** src/backend/utils/misc/postgresql.conf.sample	18 Feb 2002 06:42:54 -0000	1.29
--- src/backend/utils/misc/postgresql.conf.sample	25 Feb 2002 06:57:10 -0000
***************
*** 108,115 ****
  
  
  #
! #	Debug display
  #
  #silent_mode = false
  
  #log_connections = false
--- 108,120 ----
  
  
  #
! #	Message display
  #
+ 
+ #server_min_messages = log	# Values, in order of decreasing detail:
+ 				#  debug, info, log, notice, error, fatal, panic
+ #client_min_messages = log	# Values, in order of decreasing detail:
+ 				#  debug, log, info, notice, error
  #silent_mode = false
  
  #log_connections = false
Index: src/include/utils/elog.h
===================================================================
RCS file: /cvsroot/pgsql/src/include/utils/elog.h,v
retrieving revision 1.30
diff -c -r1.30 elog.h
*** src/include/utils/elog.h	5 Nov 2001 17:46:36 -0000	1.30
--- src/include/utils/elog.h	25 Feb 2002 06:57:10 -0000
***************
*** 15,29 ****
  #define ELOG_H
  
  /* Error level codes */
! #define NOTICE	0				/* random info, sent to frontend */
! #define ERROR	(-1)			/* user error - return to known state */
! #define FATAL	1				/* fatal error - abort process */
! #define REALLYFATAL 2			/* take down the other backends with me */
! #define DEBUG	(-2)			/* debug message */
! 
! /* temporary nonsense... */
! #define STOP	REALLYFATAL
! #define LOG		DEBUG
  
  /* Configurable parameters */
  #ifdef ENABLE_SYSLOG
--- 15,27 ----
  #define ELOG_H
  
  /* Error level codes */
! #define DEBUG	10				/* sent only to server logs, label DEBUG */
! #define LOG		11				/* sent only to server logs, label LOG */
! #define INFO	12				/* sent only to client */
! #define NOTICE	13				/* important, sent to both */
! #define ERROR	14				/* user error - return to known state */
! #define FATAL	15				/* fatal error - abort process */
! #define PANIC	16				/* take down the other backends with me */
  
  /* Configurable parameters */
  #ifdef ENABLE_SYSLOG
***************
*** 32,37 ****
--- 30,39 ----
  extern bool Log_timestamp;
  extern bool Log_pid;
  
+ extern char	   *server_min_messages_str;
+ extern char	   *client_min_messages_str;
+ extern const char server_min_messages_str_default[];
+ extern const char client_min_messages_str_default[];
  
  extern void
  elog(int lev, const char *fmt,...)
***************
*** 40,44 ****
--- 42,51 ----
  __attribute__((format(printf, 2, 3)));
  
  extern int	DebugFileOpen(void);
+ 
+ extern bool check_server_min_messages(const char *lev);
+ extern void assign_server_min_messages(const char *lev);
+ extern bool check_client_min_messages(const char *lev);
+ extern void assign_client_min_messages(const char *lev);
  
  #endif   /* ELOG_H */
