1 /*-------------------------------------------------------------------------
4 * POSTGRES error reporting/logging definitions.
7 * Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
8 * Portions Copyright (c) 1994, Regents of the University of California
10 * $Id: elog.h,v 1.61 2003/08/04 00:43:32 momjian Exp $
12 *-------------------------------------------------------------------------
17 /* Error level codes */
18 #define DEBUG5 10 /* Debugging messages, in categories of
19 * decreasing detail. */
23 #define DEBUG1 14 /* used by GUC debug_* variables */
24 #define LOG 15 /* Server operational messages; sent only
25 * to server log by default. */
26 #define COMMERROR 16 /* Client communication problems; same as
27 * LOG for server reporting, but never
29 #define INFO 17 /* Informative messages that are always
30 * sent to client; is not affected by
31 * client_min_messages */
32 #define NOTICE 18 /* Helpful messages to users about query
33 * operation; sent to client and server
35 #define WARNING 19 /* Warnings */
36 #define ERROR 20 /* user error - abort transaction; return
38 /* Save ERROR value in PGERROR so it can be restored when Win32 includes
39 * modify it. We have to use a constant rather than ERROR because macros
40 * are expanded only when referenced outside macros.
45 #define FATAL 21 /* fatal error - abort process */
46 #define PANIC 22 /* take down the other backends with me */
48 /* #define DEBUG DEBUG1 */ /* Backward compatibility with pre-7.3 */
51 /* macros for representing SQLSTATE strings compactly */
52 #define PGSIXBIT(ch) (((ch) - '0') & 0x3F)
53 #define PGUNSIXBIT(val) (((val) & 0x3F) + '0')
55 #define MAKE_SQLSTATE(ch1,ch2,ch3,ch4,ch5) \
56 (PGSIXBIT(ch1) + (PGSIXBIT(ch2) << 6) + (PGSIXBIT(ch3) << 12) + \
57 (PGSIXBIT(ch4) << 18) + (PGSIXBIT(ch5) << 24))
59 /* SQLSTATE codes for errors are defined in a separate file */
60 #include "utils/errcodes.h"
63 /* Which __func__ symbol do we have, if any? */
64 #ifdef HAVE_FUNCNAME__FUNC
65 #define PG_FUNCNAME_MACRO __func__
67 #ifdef HAVE_FUNCNAME__FUNCTION
68 #define PG_FUNCNAME_MACRO __FUNCTION__
70 #define PG_FUNCNAME_MACRO NULL
76 * New-style error reporting API: to be used in this way:
78 * (errcode(ERRCODE_UNDEFINED_CURSOR),
79 * errmsg("portal \"%s\" not found", stmt->portalname),
80 * ... other errxxx() fields as needed ...));
82 * The error level is required, and so is a primary error message (errmsg
83 * or errmsg_internal). All else is optional. errcode() defaults to
84 * ERRCODE_INTERNAL_ERROR if elevel is ERROR or more, ERRCODE_WARNING
85 * if elevel is WARNING, or ERRCODE_SUCCESSFUL_COMPLETION if elevel is
89 #define ereport(elevel, rest) \
90 (errstart(elevel, __FILE__, __LINE__, PG_FUNCNAME_MACRO) ? \
91 (errfinish rest) : (void) 0)
93 extern bool errstart(int elevel, const char *filename, int lineno,
94 const char *funcname);
95 extern void errfinish(int dummy,...);
97 extern int errcode(int sqlerrcode);
99 extern int errcode_for_file_access(void);
100 extern int errcode_for_socket_access(void);
103 errmsg(const char *fmt,...)
104 /* This extension allows gcc to check the format string for consistency with
105 the supplied arguments. */
106 __attribute__((format(printf, 1, 2)));
109 errmsg_internal(const char *fmt,...)
110 /* This extension allows gcc to check the format string for consistency with
111 the supplied arguments. */
112 __attribute__((format(printf, 1, 2)));
115 errdetail(const char *fmt,...)
116 /* This extension allows gcc to check the format string for consistency with
117 the supplied arguments. */
118 __attribute__((format(printf, 1, 2)));
121 errhint(const char *fmt,...)
122 /* This extension allows gcc to check the format string for consistency with
123 the supplied arguments. */
124 __attribute__((format(printf, 1, 2)));
127 errcontext(const char *fmt,...)
128 /* This extension allows gcc to check the format string for consistency with
129 the supplied arguments. */
130 __attribute__((format(printf, 1, 2)));
132 extern int errfunction(const char *funcname);
133 extern int errposition(int cursorpos);
137 * Old-style error reporting API: to be used in this way:
138 * elog(ERROR, "portal \"%s\" not found", stmt->portalname);
141 #define elog errstart(ERROR, __FILE__, __LINE__, PG_FUNCNAME_MACRO), elog_finish
144 elog_finish(int elevel, const char *fmt,...)
145 /* This extension allows gcc to check the format string for consistency with
146 the supplied arguments. */
147 __attribute__((format(printf, 2, 3)));
150 /* Support for attaching context information to error reports */
152 typedef struct ErrorContextCallback
154 struct ErrorContextCallback *previous;
155 void (*callback) (void *arg);
157 } ErrorContextCallback;
159 extern DLLIMPORT ErrorContextCallback *error_context_stack;
162 /* GUC-configurable parameters */
166 PGERROR_TERSE, /* single-line error messages */
167 PGERROR_DEFAULT, /* recommended style */
168 PGERROR_VERBOSE /* all the facts, ma'am */
171 extern PGErrorVerbosity Log_error_verbosity;
172 extern bool Log_timestamp;
176 extern int Use_syslog;
180 /* Other exported functions */
181 extern void DebugFileOpen(void);