OSDN Git Service

faa4783d4eb5b744327f7c7f9a0a5f58dc0d0c54
[pg-rex/syncrep.git] / src / include / utils / elog.h
1 /*-------------------------------------------------------------------------
2  *
3  * elog.h
4  *        POSTGRES error reporting/logging definitions.
5  *
6  *
7  * Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
8  * Portions Copyright (c) 1994, Regents of the University of California
9  *
10  * $Id: elog.h,v 1.61 2003/08/04 00:43:32 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 */
36 #define ERROR           20                      /* user error - abort transaction; return
37                                                                  * to known state */
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.
41  */
42 #ifdef WIN32
43 #define PGERROR         20
44 #endif
45 #define FATAL           21                      /* fatal error - abort process */
46 #define PANIC           22                      /* take down the other backends with me */
47
48  /* #define DEBUG DEBUG1 */     /* Backward compatibility with pre-7.3 */
49
50
51 /* macros for representing SQLSTATE strings compactly */
52 #define PGSIXBIT(ch)    (((ch) - '0') & 0x3F)
53 #define PGUNSIXBIT(val) (((val) & 0x3F) + '0')
54
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))
58
59 /* SQLSTATE codes for errors are defined in a separate file */
60 #include "utils/errcodes.h"
61
62
63 /* Which __func__ symbol do we have, if any? */
64 #ifdef HAVE_FUNCNAME__FUNC
65 #define PG_FUNCNAME_MACRO       __func__
66 #else
67 #ifdef HAVE_FUNCNAME__FUNCTION
68 #define PG_FUNCNAME_MACRO       __FUNCTION__
69 #else
70 #define PG_FUNCNAME_MACRO       NULL
71 #endif
72 #endif
73
74
75 /*----------
76  * New-style error reporting API: to be used in this way:
77  *              ereport(ERROR,
78  *                              (errcode(ERRCODE_UNDEFINED_CURSOR),
79  *                               errmsg("portal \"%s\" not found", stmt->portalname),
80  *                               ... other errxxx() fields as needed ...));
81  *
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
86  * NOTICE or below.
87  *----------
88  */
89 #define ereport(elevel, rest)  \
90         (errstart(elevel, __FILE__, __LINE__, PG_FUNCNAME_MACRO) ? \
91          (errfinish rest) : (void) 0)
92
93 extern bool errstart(int elevel, const char *filename, int lineno,
94                  const char *funcname);
95 extern void errfinish(int dummy,...);
96
97 extern int      errcode(int sqlerrcode);
98
99 extern int      errcode_for_file_access(void);
100 extern int      errcode_for_socket_access(void);
101
102 extern int
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)));
107
108 extern int
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)));
113
114 extern int
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)));
119
120 extern int
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)));
125
126 extern int
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)));
131
132 extern int      errfunction(const char *funcname);
133 extern int      errposition(int cursorpos);
134
135
136 /*----------
137  * Old-style error reporting API: to be used in this way:
138  *              elog(ERROR, "portal \"%s\" not found", stmt->portalname);
139  *----------
140  */
141 #define elog    errstart(ERROR, __FILE__, __LINE__, PG_FUNCNAME_MACRO), elog_finish
142
143 extern void
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)));
148
149
150 /* Support for attaching context information to error reports */
151
152 typedef struct ErrorContextCallback
153 {
154         struct ErrorContextCallback *previous;
155         void            (*callback) (void *arg);
156         void       *arg;
157 }       ErrorContextCallback;
158
159 extern DLLIMPORT ErrorContextCallback *error_context_stack;
160
161
162 /* GUC-configurable parameters */
163
164 typedef enum
165 {
166         PGERROR_TERSE,                          /* single-line error messages */
167         PGERROR_DEFAULT,                        /* recommended style */
168         PGERROR_VERBOSE                         /* all the facts, ma'am */
169 }       PGErrorVerbosity;
170
171 extern PGErrorVerbosity Log_error_verbosity;
172 extern bool Log_timestamp;
173 extern bool Log_pid;
174
175 #ifdef HAVE_SYSLOG
176 extern int      Use_syslog;
177 #endif
178
179
180 /* Other exported functions */
181 extern void DebugFileOpen(void);
182
183 #endif   /* ELOG_H */