1/*-------------------------------------------------------------------------
2 * Logging framework for frontend programs
4 * Copyright (c) 2018-2025, PostgreSQL Global Development Group
6 * src/include/common/logging.h
8 *-------------------------------------------------------------------------
10#ifndef COMMON_LOGGING_H
11#define COMMON_LOGGING_H
14 * Log levels are informational only. They do not affect program flow.
19 * Not initialized yet (not to be used as an actual message log level).
24 * Low level messages that are normally off by default.
29 * Any program messages that go to stderr, shown by default. (The
30 * program's normal output should go to stdout and not use the logging
36 * Warnings and "almost" errors, depends on the program
46 * Turn all logging off (not to be used as an actual message log level).
52 * __pg_log_level is the minimum log level that will actually be shown.
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 of
59 * this enum, for consistency.
64 * The primary message. Try to keep it to one line; follow the backend's
65 * style guideline for primary messages.
70 * Additional detail. Follow the backend's style guideline for detail
76 * Hint (not guaranteed correct) about how to fix the problem. Follow the
77 * backend's style guideline for hint messages.
83 * Kind of a hack to be able to produce the psql output exactly as required by
84 * the regression tests.
86 #define PG_LOG_FLAG_TERSE 1
96 const char *pg_restrict fmt,...)
99 const
char *pg_restrict fmt, va_list ap)
103 * Preferred style is to use these macros to perform logging; don't call
104 * pg_log_generic[_v] directly, except perhaps in error interface code.
106 #define pg_log_error(...) \
107 pg_log_generic(PG_LOG_ERROR, PG_LOG_PRIMARY, __VA_ARGS__)
109 #define pg_log_error_detail(...) \
110 pg_log_generic(PG_LOG_ERROR, PG_LOG_DETAIL, __VA_ARGS__)
112 #define pg_log_error_hint(...) \
113 pg_log_generic(PG_LOG_ERROR, PG_LOG_HINT, __VA_ARGS__)
115 #define pg_log_warning(...) \
116 pg_log_generic(PG_LOG_WARNING, PG_LOG_PRIMARY, __VA_ARGS__)
118 #define pg_log_warning_detail(...) \
119 pg_log_generic(PG_LOG_WARNING, PG_LOG_DETAIL, __VA_ARGS__)
121 #define pg_log_warning_hint(...) \
122 pg_log_generic(PG_LOG_WARNING, PG_LOG_HINT, __VA_ARGS__)
124 #define pg_log_info(...) \
125 pg_log_generic(PG_LOG_INFO, PG_LOG_PRIMARY, __VA_ARGS__)
127 #define pg_log_info_detail(...) \
128 pg_log_generic(PG_LOG_INFO, PG_LOG_DETAIL, __VA_ARGS__)
130 #define pg_log_info_hint(...) \
131 pg_log_generic(PG_LOG_INFO, PG_LOG_HINT, __VA_ARGS__)
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__); \
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__); \
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__); \
149 * A common shortcut: pg_log_error() and immediately exit(1).
151 #define pg_fatal(...) do { \
152 pg_log_generic(PG_LOG_ERROR, PG_LOG_PRIMARY, __VA_ARGS__); \
157 * Use these variants for "can't happen" cases, if it seems translating their
158 * messages would be a waste of effort.
160 #define pg_log_error_internal(...) pg_log_error(__VA_ARGS__)
161 #define pg_fatal_internal(...) pg_fatal(__VA_ARGS__)
163#endif /* COMMON_LOGGING_H */
#define pg_attribute_printf(f, a)
void pg_logging_increase_verbosity(void)
void pg_logging_init(const char *argv0)
void pg_logging_set_locus_callback(void(*cb)(const char **filename, uint64 *lineno))
void pg_logging_config(int new_flags)
void pg_logging_set_level(enum pg_log_level new_level)
void pg_log_generic(enum pg_log_level level, enum pg_log_part part, const char *pg_restrict fmt,...) pg_attribute_printf(3
void pg_logging_set_pre_callback(void(*cb)(void))
enum pg_log_level __pg_log_level
void void pg_log_generic_v(enum pg_log_level level, enum pg_log_part part, const char *pg_restrict fmt, va_list ap) pg_attribute_printf(3