1 /*-------------------------------------------------------------------------
4 * POSTGRES error reporting/logging definitions.
7 * Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group
8 * Portions Copyright (c) 1994, Regents of the University of California
10 * $PostgreSQL: pgsql/src/include/utils/elog.h,v 1.70 2004/07/06 19:51:59 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. NOTICE is for expected messages
36 * like implicit sequence creation by SERIAL.
37 * WARNING is for unexpected messages.
39 #define ERROR 20 /* user error - abort transaction; return
41 /* Save ERROR value in PGERROR so it can be restored when Win32 includes
42 * modify it. We have to use a constant rather than ERROR because macros
43 * are expanded only when referenced outside macros.
48 #define FATAL 21 /* fatal error - abort process */
49 #define PANIC 22 /* take down the other backends with me */
51 /* #define DEBUG DEBUG1 */ /* Backward compatibility with pre-7.3 */
54 /* macros for representing SQLSTATE strings compactly */
55 #define PGSIXBIT(ch) (((ch) - '0') & 0x3F)
56 #define PGUNSIXBIT(val) (((val) & 0x3F) + '0')
58 #define MAKE_SQLSTATE(ch1,ch2,ch3,ch4,ch5) \
59 (PGSIXBIT(ch1) + (PGSIXBIT(ch2) << 6) + (PGSIXBIT(ch3) << 12) + \
60 (PGSIXBIT(ch4) << 18) + (PGSIXBIT(ch5) << 24))
62 /* SQLSTATE codes for errors are defined in a separate file */
63 #include "utils/errcodes.h"
66 /* Which __func__ symbol do we have, if any? */
67 #ifdef HAVE_FUNCNAME__FUNC
68 #define PG_FUNCNAME_MACRO __func__
70 #ifdef HAVE_FUNCNAME__FUNCTION
71 #define PG_FUNCNAME_MACRO __FUNCTION__
73 #define PG_FUNCNAME_MACRO NULL
79 * New-style error reporting API: to be used in this way:
81 * (errcode(ERRCODE_UNDEFINED_CURSOR),
82 * errmsg("portal \"%s\" not found", stmt->portalname),
83 * ... other errxxx() fields as needed ...));
85 * The error level is required, and so is a primary error message (errmsg
86 * or errmsg_internal). All else is optional. errcode() defaults to
87 * ERRCODE_INTERNAL_ERROR if elevel is ERROR or more, ERRCODE_WARNING
88 * if elevel is WARNING, or ERRCODE_SUCCESSFUL_COMPLETION if elevel is
92 #define ereport(elevel, rest) \
93 (errstart(elevel, __FILE__, __LINE__, PG_FUNCNAME_MACRO) ? \
94 (errfinish rest) : (void) 0)
96 extern bool errstart(int elevel, const char *filename, int lineno,
97 const char *funcname);
98 extern void errfinish(int dummy,...);
100 extern int errcode(int sqlerrcode);
102 extern int errcode_for_file_access(void);
103 extern int errcode_for_socket_access(void);
106 errmsg(const char *fmt,...)
107 /* This extension allows gcc to check the format string for consistency with
108 the supplied arguments. */
109 __attribute__((format(printf, 1, 2)));
112 errmsg_internal(const char *fmt,...)
113 /* This extension allows gcc to check the format string for consistency with
114 the supplied arguments. */
115 __attribute__((format(printf, 1, 2)));
118 errdetail(const char *fmt,...)
119 /* This extension allows gcc to check the format string for consistency with
120 the supplied arguments. */
121 __attribute__((format(printf, 1, 2)));
124 errhint(const char *fmt,...)
125 /* This extension allows gcc to check the format string for consistency with
126 the supplied arguments. */
127 __attribute__((format(printf, 1, 2)));
130 errcontext(const char *fmt,...)
131 /* This extension allows gcc to check the format string for consistency with
132 the supplied arguments. */
133 __attribute__((format(printf, 1, 2)));
135 extern int errfunction(const char *funcname);
136 extern int errposition(int cursorpos);
138 extern int internalerrposition(int cursorpos);
139 extern int internalerrquery(const char *query);
141 extern int geterrposition(void);
142 extern int getinternalerrposition(void);
146 * Old-style error reporting API: to be used in this way:
147 * elog(ERROR, "portal \"%s\" not found", stmt->portalname);
150 #define elog errstart(ERROR, __FILE__, __LINE__, PG_FUNCNAME_MACRO), elog_finish
153 elog_finish(int elevel, const char *fmt,...)
154 /* This extension allows gcc to check the format string for consistency with
155 the supplied arguments. */
156 __attribute__((format(printf, 2, 3)));
159 /* Support for attaching context information to error reports */
161 typedef struct ErrorContextCallback
163 struct ErrorContextCallback *previous;
164 void (*callback) (void *arg);
166 } ErrorContextCallback;
168 extern DLLIMPORT ErrorContextCallback *error_context_stack;
171 /* GUC-configurable parameters */
175 PGERROR_TERSE, /* single-line error messages */
176 PGERROR_DEFAULT, /* recommended style */
177 PGERROR_VERBOSE /* all the facts, ma'am */
180 extern PGErrorVerbosity Log_error_verbosity;
181 extern char *Log_line_prefix;
182 extern unsigned int Log_destination;
184 /* Log destination bitmap */
185 #define LOG_DESTINATION_STDERR 1
186 #define LOG_DESTINATION_SYSLOG 2
187 #define LOG_DESTINATION_EVENTLOG 4
189 /* Other exported functions */
190 extern void DebugFileOpen(void);
193 * Write errors to stderr (or by equal means when stderr is
194 * not available). Used before ereport/elog can be used
195 * safely (memory context, GUC load etc)
197 extern void write_stderr(const char *fmt,...)
198 /* This extension allows gcc to check the format string for consistency with
199 the supplied arguments. */
200 __attribute__((format(printf, 1, 2)));