]> granicus.if.org Git - postgresql/blob - src/include/utils/elog.h
Add comment describing ereport() NOTICE/WARNING distinction.
[postgresql] / src / include / utils / elog.h
1 /*-------------------------------------------------------------------------
2  *
3  * elog.h
4  *        POSTGRES error reporting/logging definitions.
5  *
6  *
7  * Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group
8  * Portions Copyright (c) 1994, Regents of the University of California
9  *
10  * $PostgreSQL: pgsql/src/include/utils/elog.h,v 1.70 2004/07/06 19:51:59 momjian Exp $
11  *
12  *-------------------------------------------------------------------------
13  */
14 #ifndef ELOG_H
15 #define ELOG_H
16
17 /* Error level codes */
18 #define DEBUG5          10                      /* Debugging messages, in categories of
19                                                                  * decreasing detail. */
20 #define DEBUG4          11
21 #define DEBUG3          12
22 #define DEBUG2          13
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
28                                                                  * sent to client. */
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
34                                                                  * log by default. */
35 #define WARNING         19                      /* Warnings.  NOTICE is for expected messages
36                                                                  * like implicit sequence creation by SERIAL.
37                                                                  * WARNING is for unexpected messages.
38                                                                  */
39 #define ERROR           20                      /* user error - abort transaction; return
40                                                                  * to known state */
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.
44  */
45 #ifdef WIN32
46 #define PGERROR         20
47 #endif
48 #define FATAL           21                      /* fatal error - abort process */
49 #define PANIC           22                      /* take down the other backends with me */
50
51  /* #define DEBUG DEBUG1 */     /* Backward compatibility with pre-7.3 */
52
53
54 /* macros for representing SQLSTATE strings compactly */
55 #define PGSIXBIT(ch)    (((ch) - '0') & 0x3F)
56 #define PGUNSIXBIT(val) (((val) & 0x3F) + '0')
57
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))
61
62 /* SQLSTATE codes for errors are defined in a separate file */
63 #include "utils/errcodes.h"
64
65
66 /* Which __func__ symbol do we have, if any? */
67 #ifdef HAVE_FUNCNAME__FUNC
68 #define PG_FUNCNAME_MACRO       __func__
69 #else
70 #ifdef HAVE_FUNCNAME__FUNCTION
71 #define PG_FUNCNAME_MACRO       __FUNCTION__
72 #else
73 #define PG_FUNCNAME_MACRO       NULL
74 #endif
75 #endif
76
77
78 /*----------
79  * New-style error reporting API: to be used in this way:
80  *              ereport(ERROR,
81  *                              (errcode(ERRCODE_UNDEFINED_CURSOR),
82  *                               errmsg("portal \"%s\" not found", stmt->portalname),
83  *                               ... other errxxx() fields as needed ...));
84  *
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
89  * NOTICE or below.
90  *----------
91  */
92 #define ereport(elevel, rest)  \
93         (errstart(elevel, __FILE__, __LINE__, PG_FUNCNAME_MACRO) ? \
94          (errfinish rest) : (void) 0)
95
96 extern bool errstart(int elevel, const char *filename, int lineno,
97                  const char *funcname);
98 extern void errfinish(int dummy,...);
99
100 extern int      errcode(int sqlerrcode);
101
102 extern int      errcode_for_file_access(void);
103 extern int      errcode_for_socket_access(void);
104
105 extern int
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)));
110
111 extern int
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)));
116
117 extern int
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)));
122
123 extern int
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)));
128
129 extern int
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)));
134
135 extern int      errfunction(const char *funcname);
136 extern int      errposition(int cursorpos);
137
138 extern int      internalerrposition(int cursorpos);
139 extern int      internalerrquery(const char *query);
140
141 extern int      geterrposition(void);
142 extern int      getinternalerrposition(void);
143
144
145 /*----------
146  * Old-style error reporting API: to be used in this way:
147  *              elog(ERROR, "portal \"%s\" not found", stmt->portalname);
148  *----------
149  */
150 #define elog    errstart(ERROR, __FILE__, __LINE__, PG_FUNCNAME_MACRO), elog_finish
151
152 extern void
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)));
157
158
159 /* Support for attaching context information to error reports */
160
161 typedef struct ErrorContextCallback
162 {
163         struct ErrorContextCallback *previous;
164         void            (*callback) (void *arg);
165         void       *arg;
166 } ErrorContextCallback;
167
168 extern DLLIMPORT ErrorContextCallback *error_context_stack;
169
170
171 /* GUC-configurable parameters */
172
173 typedef enum
174 {
175         PGERROR_TERSE,                          /* single-line error messages */
176         PGERROR_DEFAULT,                        /* recommended style */
177         PGERROR_VERBOSE                         /* all the facts, ma'am */
178 } PGErrorVerbosity;
179
180 extern PGErrorVerbosity Log_error_verbosity;
181 extern char *Log_line_prefix;
182 extern unsigned int Log_destination;
183
184 /* Log destination bitmap */
185 #define LOG_DESTINATION_STDERR   1
186 #define LOG_DESTINATION_SYSLOG   2
187 #define LOG_DESTINATION_EVENTLOG 4
188
189 /* Other exported functions */
190 extern void DebugFileOpen(void);
191
192 /*
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)
196  */
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)));
201
202 #endif   /* ELOG_H */