PostgreSQL Source Code  git master
logging.h
Go to the documentation of this file.
1 /*-------------------------------------------------------------------------
2  * Logging framework for frontend programs
3  *
4  * Copyright (c) 2018-2019, PostgreSQL Global Development Group
5  *
6  * src/include/common/logging.h
7  *
8  *-------------------------------------------------------------------------
9  */
10 #ifndef COMMON_LOGGING_H
11 #define COMMON_LOGGING_H
12 
13 /*
14  * Log levels are informational only. They do not affect program flow.
15  */
17 {
18  /*
19  * Not initialized yet
20  */
22 
23  /*
24  * Low level messages that are normally off by default.
25  */
27 
28  /*
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
31  * system.)
32  */
34 
35  /*
36  * Warnings and "almost" errors, depends on the program
37  */
39 
40  /*
41  * Errors
42  */
44 
45  /*
46  * Severe errors that cause program termination. (One-shot programs may
47  * chose to label even fatal errors as merely "errors". The distinction
48  * is up to the program.)
49  */
51 
52  /*
53  * Turn all logging off.
54  */
56 };
57 
58 extern enum pg_log_level __pg_log_level;
59 
60 /*
61  * Kind of a hack to be able to produce the psql output exactly as required by
62  * the regression tests.
63  */
64 #define PG_LOG_FLAG_TERSE 1
65 
66 void pg_logging_init(const char *argv0);
67 void pg_logging_config(int new_flags);
68 void pg_logging_set_level(enum pg_log_level new_level);
69 void pg_logging_set_pre_callback(void (*cb) (void));
70 void pg_logging_set_locus_callback(void (*cb) (const char **filename, uint64 *lineno));
71 
72 void pg_log_generic(enum pg_log_level level, const char *pg_restrict fmt,...) pg_attribute_printf(2, 3);
73 void pg_log_generic_v(enum pg_log_level level, const char *pg_restrict fmt, va_list ap) pg_attribute_printf(2, 0);
74 
75 #define pg_log_fatal(...) do { \
76  if (likely(__pg_log_level <= PG_LOG_FATAL)) pg_log_generic(PG_LOG_FATAL, __VA_ARGS__); \
77  } while(0)
78 
79 #define pg_log_error(...) do { \
80  if (likely(__pg_log_level <= PG_LOG_ERROR)) pg_log_generic(PG_LOG_ERROR, __VA_ARGS__); \
81  } while(0)
82 
83 #define pg_log_warning(...) do { \
84  if (likely(__pg_log_level <= PG_LOG_WARNING)) pg_log_generic(PG_LOG_WARNING, __VA_ARGS__); \
85  } while(0)
86 
87 #define pg_log_info(...) do { \
88  if (likely(__pg_log_level <= PG_LOG_INFO)) pg_log_generic(PG_LOG_INFO, __VA_ARGS__); \
89  } while(0)
90 
91 #define pg_log_debug(...) do { \
92  if (unlikely(__pg_log_level <= PG_LOG_DEBUG)) pg_log_generic(PG_LOG_DEBUG, __VA_ARGS__); \
93  } while(0)
94 
95 #endif /* COMMON_LOGGING_H */
static char * argv0
Definition: pg_ctl.c:97
void pg_logging_set_level(enum pg_log_level new_level)
Definition: logging.c:108
void pg_logging_set_locus_callback(void(*cb)(const char **filename, uint64 *lineno))
Definition: logging.c:120
void pg_logging_config(int new_flags)
Definition: logging.c:102
pg_log_level
Definition: logging.h:16
enum pg_log_level __pg_log_level
Definition: logging.c:16
void void pg_log_generic_v(enum pg_log_level level, const char *pg_restrict fmt, va_list ap) pg_attribute_printf(2
#define pg_attribute_printf(f, a)
Definition: c.h:132
void pg_log_generic(enum pg_log_level level, const char *pg_restrict fmt,...) pg_attribute_printf(2
void pg_logging_init(const char *argv0)
Definition: logging.c:39
void pg_logging_set_pre_callback(void(*cb)(void))
Definition: logging.c:114
static char * filename
Definition: pg_dumpall.c:90