Eneboo - Documentación para desarrolladores
src/libpq/include/utils/elog.h
Ir a la documentación de este archivo.
00001 /*-------------------------------------------------------------------------
00002  *
00003  * elog.h
00004  *        POSTGRES error reporting/logging definitions.
00005  *
00006  *
00007  * Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
00008  * Portions Copyright (c) 1994, Regents of the University of California
00009  *
00010  * $PostgreSQL: pgsql/src/include/utils/elog.h,v 1.81 2005/10/15 02:49:46 momjian Exp $
00011  *
00012  *-------------------------------------------------------------------------
00013  */
00014 #ifndef ELOG_H
00015 #define ELOG_H
00016 
00017 #include <setjmp.h>
00018 
00019 /* Error level codes */
00020 #define DEBUG5          10                      /* Debugging messages, in categories of
00021                                                                  * decreasing detail. */
00022 #define DEBUG4          11
00023 #define DEBUG3          12
00024 #define DEBUG2          13
00025 #define DEBUG1          14                      /* used by GUC debug_* variables */
00026 #define LOG                     15                      /* Server operational messages; sent only to
00027                                                                  * server log by default. */
00028 #define COMMERROR       16                      /* Client communication problems; same as LOG
00029                                                                  * for server reporting, but never sent to
00030                                                                  * client. */
00031 #define INFO            17                      /* Informative messages that are always sent
00032                                                                  * to client;  is not affected by
00033                                                                  * client_min_messages */
00034 #define NOTICE          18                      /* Helpful messages to users about query
00035                                                                  * operation;  sent to client and server log
00036                                                                  * by default. */
00037 #define WARNING         19                      /* Warnings.  NOTICE is for expected messages
00038                                                                  * like implicit sequence creation by SERIAL.
00039                                                                  * WARNING is for unexpected messages. */
00040 #define ERROR           20                      /* user error - abort transaction; return to
00041                                                                  * known state */
00042 /* Save ERROR value in PGERROR so it can be restored when Win32 includes
00043  * modify it.  We have to use a constant rather than ERROR because macros
00044  * are expanded only when referenced outside macros.
00045  */
00046 #ifdef WIN32
00047 #define PGERROR         20
00048 #endif
00049 #define FATAL           21                      /* fatal error - abort process */
00050 #define PANIC           22                      /* take down the other backends with me */
00051 
00052  /* #define DEBUG DEBUG1 */     /* Backward compatibility with pre-7.3 */
00053 
00054 
00055 /* macros for representing SQLSTATE strings compactly */
00056 #define PGSIXBIT(ch)    (((ch) - '0') & 0x3F)
00057 #define PGUNSIXBIT(val) (((val) & 0x3F) + '0')
00058 
00059 #define MAKE_SQLSTATE(ch1,ch2,ch3,ch4,ch5)      \
00060         (PGSIXBIT(ch1) + (PGSIXBIT(ch2) << 6) + (PGSIXBIT(ch3) << 12) + \
00061          (PGSIXBIT(ch4) << 18) + (PGSIXBIT(ch5) << 24))
00062 
00063 /* These macros depend on the fact that '0' becomes a zero in SIXBIT */
00064 #define ERRCODE_TO_CATEGORY(ec)  ((ec) & ((1 << 12) - 1))
00065 #define ERRCODE_IS_CATEGORY(ec)  (((ec) & ~((1 << 12) - 1)) == 0)
00066 
00067 /* SQLSTATE codes for errors are defined in a separate file */
00068 #include "utils/errcodes.h"
00069 
00070 /* Which __func__ symbol do we have, if any? */
00071 #ifdef HAVE_FUNCNAME__FUNC
00072 //#include "HISTORY"
00073 #define PG_FUNCNAME_MACRO       __func__
00074 #else
00075 #ifdef HAVE_FUNCNAME__FUNCTION
00076 #define PG_FUNCNAME_MACRO       __FUNCTION__
00077 #else
00078 #define PG_FUNCNAME_MACRO       NULL
00079 #endif
00080 #endif
00081 
00082 
00083 /*----------
00084  * New-style error reporting API: to be used in this way:
00085  *              ereport(ERROR,
00086  *                              (errcode(ERRCODE_UNDEFINED_CURSOR),
00087  *                               errmsg("portal \"%s\" not found", stmt->portalname),
00088  *                               ... other errxxx() fields as needed ...));
00089  *
00090  * The error level is required, and so is a primary error message (errmsg
00091  * or errmsg_internal).  All else is optional.  errcode() defaults to
00092  * ERRCODE_INTERNAL_ERROR if elevel is ERROR or more, ERRCODE_WARNING
00093  * if elevel is WARNING, or ERRCODE_SUCCESSFUL_COMPLETION if elevel is
00094  * NOTICE or below.
00095  *----------
00096  */
00097 #define ereport(elevel, rest)  \
00098         (errstart(elevel, __FILE__, __LINE__, PG_FUNCNAME_MACRO) ? \
00099          (errfinish rest) : (void) 0)
00100 
00101 extern bool errstart(int elevel, const char *filename, int lineno,
00102                  const char *funcname);
00103 extern void errfinish(int dummy,...);
00104 
00105 extern int      errcode(int sqlerrcode);
00106 
00107 extern int      errcode_for_file_access(void);
00108 extern int      errcode_for_socket_access(void);
00109 
00110 extern int
00111 errmsg(const char *fmt,...)
00112 /* This extension allows gcc to check the format string for consistency with
00113    the supplied arguments. */
00114 __attribute__((format(printf, 1, 2)));
00115 
00116 extern int
00117 errmsg_internal(const char *fmt,...)
00118 /* This extension allows gcc to check the format string for consistency with
00119    the supplied arguments. */
00120 __attribute__((format(printf, 1, 2)));
00121 
00122 extern int
00123 errdetail(const char *fmt,...)
00124 /* This extension allows gcc to check the format string for consistency with
00125    the supplied arguments. */
00126 __attribute__((format(printf, 1, 2)));
00127 
00128 extern int
00129 errhint(const char *fmt,...)
00130 /* This extension allows gcc to check the format string for consistency with
00131    the supplied arguments. */
00132 __attribute__((format(printf, 1, 2)));
00133 
00134 extern int
00135 errcontext(const char *fmt,...)
00136 /* This extension allows gcc to check the format string for consistency with
00137    the supplied arguments. */
00138 __attribute__((format(printf, 1, 2)));
00139 
00140 extern int      errfunction(const char *funcname);
00141 extern int      errposition(int cursorpos);
00142 
00143 extern int      internalerrposition(int cursorpos);
00144 extern int      internalerrquery(const char *query);
00145 
00146 extern int      geterrposition(void);
00147 extern int      getinternalerrposition(void);
00148 
00149 
00150 /*----------
00151  * Old-style error reporting API: to be used in this way:
00152  *              elog(ERROR, "portal \"%s\" not found", stmt->portalname);
00153  *----------
00154  */
00155 #define elog    elog_start(__FILE__, __LINE__, PG_FUNCNAME_MACRO), elog_finish
00156 
00157 extern void elog_start(const char *filename, int lineno, const char *funcname);
00158 extern void
00159 elog_finish(int elevel, const char *fmt,...)
00160 /* This extension allows gcc to check the format string for consistency with
00161    the supplied arguments. */
00162 __attribute__((format(printf, 2, 3)));
00163 
00164 
00165 /* Support for attaching context information to error reports */
00166 
00167 typedef struct ErrorContextCallback
00168 {
00169         struct ErrorContextCallback *previous;
00170         void            (*callback) (void *arg);
00171         void       *arg;
00172 } ErrorContextCallback;
00173 
00174 extern DLLIMPORT ErrorContextCallback *error_context_stack;
00175 
00176 
00177 /*----------
00178  * API for catching ereport(ERROR) exits.  Use these macros like so:
00179  *
00180  *              PG_TRY();
00181  *              {
00182  *                      ... code that might throw ereport(ERROR) ...
00183  *              }
00184  *              PG_CATCH();
00185  *              {
00186  *                      ... error recovery code ...
00187  *              }
00188  *              PG_END_TRY();
00189  *
00190  * (The braces are not actually necessary, but are recommended so that
00191  * pg_indent will indent the construct nicely.)  The error recovery code
00192  * can optionally do PG_RE_THROW() to propagate the same error outwards.
00193  *
00194  * Note: while the system will correctly propagate any new ereport(ERROR)
00195  * occurring in the recovery section, there is a small limit on the number
00196  * of levels this will work for.  It's best to keep the error recovery
00197  * section simple enough that it can't generate any new errors, at least
00198  * not before popping the error stack.
00199  *----------
00200  */
00201 #define PG_TRY()  \
00202         do { \
00203                 sigjmp_buf *save_exception_stack = PG_exception_stack; \
00204                 ErrorContextCallback *save_context_stack = error_context_stack; \
00205                 sigjmp_buf local_sigjmp_buf; \
00206                 if (sigsetjmp(local_sigjmp_buf, 0) == 0) \
00207                 { \
00208                         PG_exception_stack = &local_sigjmp_buf
00209 
00210 #define PG_CATCH()      \
00211                 } \
00212                 else \
00213                 { \
00214                         PG_exception_stack = save_exception_stack; \
00215                         error_context_stack = save_context_stack
00216 
00217 #define PG_END_TRY()  \
00218                 } \
00219                 PG_exception_stack = save_exception_stack; \
00220                 error_context_stack = save_context_stack; \
00221         } while (0)
00222 
00223 #define PG_RE_THROW()  \
00224         siglongjmp(*PG_exception_stack, 1)
00225 
00226 extern DLLIMPORT sigjmp_buf *PG_exception_stack;
00227 
00228 
00229 /* Stuff that error handlers might want to use */
00230 
00231 /*
00232  * ErrorData holds the data accumulated during any one ereport() cycle.
00233  * Any non-NULL pointers must point to palloc'd data.
00234  * (The const pointers are an exception; we assume they point at non-freeable
00235  * constant strings.)
00236  */
00237 typedef struct ErrorData
00238 {
00239         int                     elevel;                 /* error level */
00240         bool            output_to_server;               /* will report to server log? */
00241         bool            output_to_client;               /* will report to client? */
00242         bool            show_funcname;  /* true to force funcname inclusion */
00243         const char *filename;           /* __FILE__ of ereport() call */
00244         int                     lineno;                 /* __LINE__ of ereport() call */
00245         const char *funcname;           /* __func__ of ereport() call */
00246         int                     sqlerrcode;             /* encoded ERRSTATE */
00247         char       *message;            /* primary error message */
00248         char       *detail;                     /* detail error message */
00249         char       *hint;                       /* hint message */
00250         char       *context;            /* context message */
00251         int                     cursorpos;              /* cursor index into query string */
00252         int                     internalpos;    /* cursor index into internalquery */
00253         char       *internalquery;      /* text of internally-generated query */
00254         int                     saved_errno;    /* errno at entry */
00255 } ErrorData;
00256 
00257 extern void EmitErrorReport(void);
00258 extern ErrorData *CopyErrorData(void);
00259 extern void FreeErrorData(ErrorData *edata);
00260 extern void FlushErrorState(void);
00261 extern void ReThrowError(ErrorData *edata);
00262 
00263 
00264 /* GUC-configurable parameters */
00265 
00266 typedef enum
00267 {
00268         PGERROR_TERSE,                          /* single-line error messages */
00269         PGERROR_DEFAULT,                        /* recommended style */
00270         PGERROR_VERBOSE                         /* all the facts, ma'am */
00271 } PGErrorVerbosity;
00272 
00273 extern PGErrorVerbosity Log_error_verbosity;
00274 extern char *Log_line_prefix;
00275 extern int      Log_destination;
00276 
00277 /* Log destination bitmap */
00278 #define LOG_DESTINATION_STDERR   1
00279 #define LOG_DESTINATION_SYSLOG   2
00280 #define LOG_DESTINATION_EVENTLOG 4
00281 
00282 /* Other exported functions */
00283 extern void DebugFileOpen(void);
00284 extern char *unpack_sql_state(int sql_state);
00285 
00286 #ifdef HAVE_SYSLOG
00287 extern void set_syslog_parameters(const char *ident, int facility);
00288 #endif
00289 
00290 /*
00291  * Write errors to stderr (or by equal means when stderr is
00292  * not available). Used before ereport/elog can be used
00293  * safely (memory context, GUC load etc)
00294  */
00295 extern void
00296 write_stderr(const char *fmt,...)
00297 /* This extension allows gcc to check the format string for consistency with
00298    the supplied arguments. */
00299 __attribute__((format(printf, 1, 2)));
00300 
00301 #endif   /* ELOG_H */
 Todo Clases Namespaces Archivos Funciones Variables 'typedefs' Enumeraciones Valores de enumeraciones Propiedades Amigas 'defines'