Team Ai
Datasetpublic

codekingpro/portable-devtools

sourceHugging Faceupdated 5mo agoView on Hugging Face
1likes15kdownloads
logging.h157 linesDownload Raw Back to common
1/*-------------------------------------------------------------------------2 * Logging framework for frontend programs3 *4 * Copyright (c) 2018-2023, PostgreSQL Global Development Group5 *6 * src/include/common/logging.h7 *8 *-------------------------------------------------------------------------9 */10#ifndef COMMON_LOGGING_H11#define COMMON_LOGGING_H12 13/*14 * Log levels are informational only.  They do not affect program flow.15 */16enum pg_log_level17{18	/*19	 * Not initialized yet (not to be used as an actual message log level).20	 */21	PG_LOG_NOTSET = 0,22 23	/*24	 * Low level messages that are normally off by default.25	 */26	PG_LOG_DEBUG,27 28	/*29	 * Any program messages that go to stderr, shown by default.  (The30	 * program's normal output should go to stdout and not use the logging31	 * system.)32	 */33	PG_LOG_INFO,34 35	/*36	 * Warnings and "almost" errors, depends on the program37	 */38	PG_LOG_WARNING,39 40	/*41	 * Errors42	 */43	PG_LOG_ERROR,44 45	/*46	 * Turn all logging off (not to be used as an actual message log level).47	 */48	PG_LOG_OFF,49};50 51/*52 * __pg_log_level is the minimum log level that will actually be shown.53 */54extern enum pg_log_level __pg_log_level;55 56/*57 * A log message can have several parts.  The primary message is required,58 * others are optional.  When emitting multiple parts, do so in the order of59 * this enum, for consistency.60 */61enum pg_log_part62{63	/*64	 * The primary message.  Try to keep it to one line; follow the backend's65	 * style guideline for primary messages.66	 */67	PG_LOG_PRIMARY,68 69	/*70	 * Additional detail.  Follow the backend's style guideline for detail71	 * messages.72	 */73	PG_LOG_DETAIL,74 75	/*76	 * Hint (not guaranteed correct) about how to fix the problem.  Follow the77	 * backend's style guideline for hint messages.78	 */79	PG_LOG_HINT,80};81 82/*83 * Kind of a hack to be able to produce the psql output exactly as required by84 * the regression tests.85 */86#define PG_LOG_FLAG_TERSE	187 88void		pg_logging_init(const char *argv0);89void		pg_logging_config(int new_flags);90void		pg_logging_set_level(enum pg_log_level new_level);91void		pg_logging_increase_verbosity(void);92void		pg_logging_set_pre_callback(void (*cb) (void));93void		pg_logging_set_locus_callback(void (*cb) (const char **filename, uint64 *lineno));94 95void		pg_log_generic(enum pg_log_level level, enum pg_log_part part,96						   const char *pg_restrict fmt,...)97			pg_attribute_printf(3, 4);98void		pg_log_generic_v(enum pg_log_level level, enum pg_log_part part,99							 const char *pg_restrict fmt, va_list ap)100			pg_attribute_printf(3, 0);101 102/*103 * Preferred style is to use these macros to perform logging; don't call104 * pg_log_generic[_v] directly, except perhaps in error interface code.105 */106#define pg_log_error(...) \107	pg_log_generic(PG_LOG_ERROR, PG_LOG_PRIMARY, __VA_ARGS__)108 109#define pg_log_error_detail(...) \110	pg_log_generic(PG_LOG_ERROR, PG_LOG_DETAIL, __VA_ARGS__)111 112#define pg_log_error_hint(...) \113	pg_log_generic(PG_LOG_ERROR, PG_LOG_HINT, __VA_ARGS__)114 115#define pg_log_warning(...) \116	pg_log_generic(PG_LOG_WARNING, PG_LOG_PRIMARY, __VA_ARGS__)117 118#define pg_log_warning_detail(...) \119	pg_log_generic(PG_LOG_WARNING, PG_LOG_DETAIL, __VA_ARGS__)120 121#define pg_log_warning_hint(...) \122	pg_log_generic(PG_LOG_WARNING, PG_LOG_HINT, __VA_ARGS__)123 124#define pg_log_info(...) \125	pg_log_generic(PG_LOG_INFO, PG_LOG_PRIMARY, __VA_ARGS__)126 127#define pg_log_info_detail(...) \128	pg_log_generic(PG_LOG_INFO, PG_LOG_DETAIL, __VA_ARGS__)129 130#define pg_log_info_hint(...) \131	pg_log_generic(PG_LOG_INFO, PG_LOG_HINT, __VA_ARGS__)132 133#define pg_log_debug(...) do { \134		if (unlikely(__pg_log_level <= PG_LOG_DEBUG)) \135			pg_log_generic(PG_LOG_DEBUG, PG_LOG_PRIMARY, __VA_ARGS__); \136	} while(0)137 138#define pg_log_debug_detail(...) do { \139		if (unlikely(__pg_log_level <= PG_LOG_DEBUG)) \140			pg_log_generic(PG_LOG_DEBUG, PG_LOG_DETAIL, __VA_ARGS__); \141	} while(0)142 143#define pg_log_debug_hint(...) do { \144		if (unlikely(__pg_log_level <= PG_LOG_DEBUG)) \145			pg_log_generic(PG_LOG_DEBUG, PG_LOG_HINT, __VA_ARGS__); \146	} while(0)147 148/*149 * A common shortcut: pg_log_error() and immediately exit(1).150 */151#define pg_fatal(...) do { \152		pg_log_generic(PG_LOG_ERROR, PG_LOG_PRIMARY, __VA_ARGS__); \153		exit(1); \154	} while(0)155 156#endif							/* COMMON_LOGGING_H */157 
codekingpro/portable-devtools · Team Ai