PostgreSQL Source Code git master
Loading...
Searching...
No Matches
logging.h File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define PG_LOG_FLAG_TERSE   1
 
#define pg_log_error(...)    pg_log_generic(PG_LOG_ERROR, PG_LOG_PRIMARY, __VA_ARGS__)
 
#define pg_log_error_detail(...)    pg_log_generic(PG_LOG_ERROR, PG_LOG_DETAIL, __VA_ARGS__)
 
#define pg_log_error_hint(...)    pg_log_generic(PG_LOG_ERROR, PG_LOG_HINT, __VA_ARGS__)
 
#define pg_log_warning(...)    pg_log_generic(PG_LOG_WARNING, PG_LOG_PRIMARY, __VA_ARGS__)
 
#define pg_log_warning_detail(...)    pg_log_generic(PG_LOG_WARNING, PG_LOG_DETAIL, __VA_ARGS__)
 
#define pg_log_warning_hint(...)    pg_log_generic(PG_LOG_WARNING, PG_LOG_HINT, __VA_ARGS__)
 
#define pg_log_info(...)    pg_log_generic(PG_LOG_INFO, PG_LOG_PRIMARY, __VA_ARGS__)
 
#define pg_log_info_detail(...)    pg_log_generic(PG_LOG_INFO, PG_LOG_DETAIL, __VA_ARGS__)
 
#define pg_log_info_hint(...)    pg_log_generic(PG_LOG_INFO, PG_LOG_HINT, __VA_ARGS__)
 
#define pg_log_debug(...)
 
#define pg_log_debug_detail(...)
 
#define pg_log_debug_hint(...)
 
#define pg_fatal(...)
 
#define pg_log_error_internal(...)   pg_log_error(__VA_ARGS__)
 
#define pg_fatal_internal(...)   pg_fatal(__VA_ARGS__)
 

Enumerations

enum  pg_log_level {
  PG_LOG_NOTSET = 0 , PG_LOG_DEBUG , PG_LOG_INFO , PG_LOG_WARNING ,
  PG_LOG_ERROR , PG_LOG_OFF
}
 
enum  pg_log_part { PG_LOG_PRIMARY , PG_LOG_DETAIL , PG_LOG_HINT }
 

Functions

void pg_logging_init (const char *argv0)
 
void pg_logging_config (int new_flags)
 
void pg_logging_set_level (enum pg_log_level new_level)
 
void pg_logging_increase_verbosity (void)
 
void pg_logging_set_pre_callback (void(*cb)(void))
 
void pg_logging_set_locus_callback (void(*cb)(const char **filename, uint64 *lineno))
 
void pg_logging_set_logfile (FILE *logfile)
 
void pg_logging_unset_logfile (void)
 
void pg_log_generic (enum pg_log_level level, enum pg_log_part part, const char *pg_restrict fmt,...) pg_attribute_printf(3
 
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
 

Variables

enum pg_log_level __pg_log_level
 

Macro Definition Documentation

◆ pg_fatal

#define pg_fatal (   ...)
Value:
do { \
exit(1); \
} while(0)
@ PG_LOG_PRIMARY
Definition logging.h:67
@ PG_LOG_ERROR
Definition logging.h:43
static int fb(int x)

Definition at line 153 of file logging.h.

153 { \
155 exit(1); \
156 } while(0)

◆ pg_fatal_internal

#define pg_fatal_internal (   ...)    pg_fatal(__VA_ARGS__)

Definition at line 163 of file logging.h.

◆ pg_log_debug

#define pg_log_debug (   ...)
Value:
do { \
} while(0)
#define unlikely(x)
Definition c.h:438
@ PG_LOG_DEBUG
Definition logging.h:26
enum pg_log_level __pg_log_level
Definition logging.c:21

Definition at line 135 of file logging.h.

◆ pg_log_debug_detail

#define pg_log_debug_detail (   ...)
Value:

Definition at line 140 of file logging.h.

◆ pg_log_debug_hint

#define pg_log_debug_hint (   ...)
Value:

Definition at line 145 of file logging.h.

◆ pg_log_error

#define pg_log_error (   ...)     pg_log_generic(PG_LOG_ERROR, PG_LOG_PRIMARY, __VA_ARGS__)

Definition at line 108 of file logging.h.

◆ pg_log_error_detail

#define pg_log_error_detail (   ...)     pg_log_generic(PG_LOG_ERROR, PG_LOG_DETAIL, __VA_ARGS__)

Definition at line 111 of file logging.h.

◆ pg_log_error_hint

#define pg_log_error_hint (   ...)     pg_log_generic(PG_LOG_ERROR, PG_LOG_HINT, __VA_ARGS__)

Definition at line 114 of file logging.h.

◆ pg_log_error_internal

#define pg_log_error_internal (   ...)    pg_log_error(__VA_ARGS__)

Definition at line 162 of file logging.h.

◆ PG_LOG_FLAG_TERSE

#define PG_LOG_FLAG_TERSE   1

Definition at line 86 of file logging.h.

◆ pg_log_info

#define pg_log_info (   ...)     pg_log_generic(PG_LOG_INFO, PG_LOG_PRIMARY, __VA_ARGS__)

Definition at line 126 of file logging.h.

◆ pg_log_info_detail

#define pg_log_info_detail (   ...)     pg_log_generic(PG_LOG_INFO, PG_LOG_DETAIL, __VA_ARGS__)

Definition at line 129 of file logging.h.

◆ pg_log_info_hint

#define pg_log_info_hint (   ...)     pg_log_generic(PG_LOG_INFO, PG_LOG_HINT, __VA_ARGS__)

Definition at line 132 of file logging.h.

◆ pg_log_warning

#define pg_log_warning (   ...)     pg_log_generic(PG_LOG_WARNING, PG_LOG_PRIMARY, __VA_ARGS__)

Definition at line 117 of file logging.h.

◆ pg_log_warning_detail

#define pg_log_warning_detail (   ...)     pg_log_generic(PG_LOG_WARNING, PG_LOG_DETAIL, __VA_ARGS__)

Definition at line 120 of file logging.h.

◆ pg_log_warning_hint

#define pg_log_warning_hint (   ...)     pg_log_generic(PG_LOG_WARNING, PG_LOG_HINT, __VA_ARGS__)

Definition at line 123 of file logging.h.

Enumeration Type Documentation

◆ pg_log_level

Enumerator
PG_LOG_NOTSET 
PG_LOG_DEBUG 
PG_LOG_INFO 
PG_LOG_WARNING 
PG_LOG_ERROR 
PG_LOG_OFF 

Definition at line 16 of file logging.h.

17{
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 */
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 * Turn all logging off (not to be used as an actual message log level).
47 */
49};
@ PG_LOG_INFO
Definition logging.h:33
@ PG_LOG_NOTSET
Definition logging.h:21
@ PG_LOG_WARNING
Definition logging.h:38
@ PG_LOG_OFF
Definition logging.h:48

◆ pg_log_part

Enumerator
PG_LOG_PRIMARY 
PG_LOG_DETAIL 
PG_LOG_HINT 

Definition at line 61 of file logging.h.

62{
63 /*
64 * The primary message. Try to keep it to one line; follow the backend's
65 * style guideline for primary messages.
66 */
68
69 /*
70 * Additional detail. Follow the backend's style guideline for detail
71 * messages.
72 */
74
75 /*
76 * Hint (not guaranteed correct) about how to fix the problem. Follow the
77 * backend's style guideline for hint messages.
78 */
80};

Function Documentation

◆ pg_log_generic()

void pg_log_generic ( enum pg_log_level  level,
enum pg_log_part  part,
const char *pg_restrict  fmt,
  ... 
)

◆ pg_log_generic_v()

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_logging_config()

void pg_logging_config ( int  new_flags)

Definition at line 168 of file logging.c.

169{
171}
static int log_flags
Definition logging.c:24

References fb(), and log_flags.

Referenced by main(), and process_file().

◆ pg_logging_increase_verbosity()

void pg_logging_increase_verbosity ( void  )

Definition at line 187 of file logging.c.

188{
189 /*
190 * The enum values are chosen such that we have to decrease __pg_log_level
191 * in order to become more verbose.
192 */
195}
enum pg_log_level __pg_log_level
Definition logging.c:21

References __pg_log_level, and PG_LOG_NOTSET.

Referenced by main(), and main().

◆ pg_logging_init()

void pg_logging_init ( const char argv0)

Definition at line 85 of file logging.c.

86{
87 const char *pg_color_env = getenv("PG_COLOR");
88 bool log_color = false;
89 bool color_terminal = isatty(fileno(stderr));
90
91#ifdef WIN32
92
93 /*
94 * On Windows, check if environment is VT100-compatible if using a
95 * terminal.
96 */
99#endif
100
101 /* usually the default, but not on Windows */
103
106
107 if (pg_color_env)
108 {
109 if (strcmp(pg_color_env, "always") == 0 ||
110 (strcmp(pg_color_env, "auto") == 0 && color_terminal))
111 log_color = true;
112 }
113
114 if (log_color)
115 {
116 const char *pg_colors_env = getenv("PG_COLORS");
117
118 if (pg_colors_env)
119 {
120 char *colors = strdup(pg_colors_env);
121
122 if (colors)
123 {
124 char *token;
125 char *cp = colors;
126
127 while ((token = strsep(&cp, ":")))
128 {
129 char *e = strchr(token, '=');
130
131 if (e)
132 {
133 char *name;
134 char *value;
135
136 *e = '\0';
137 name = token;
138 value = e + 1;
139
140 if (strcmp(name, "error") == 0)
142 if (strcmp(name, "warning") == 0)
144 if (strcmp(name, "note") == 0)
146 if (strcmp(name, "locus") == 0)
148 }
149 }
150
151 free(colors);
152 }
153 }
154 else
155 {
160 }
161 }
162}
#define token
static struct @177 value
#define SGR_WARNING_DEFAULT
Definition logging.c:37
#define SGR_NOTE_DEFAULT
Definition logging.c:38
static const char * sgr_note
Definition logging.c:33
static const char * sgr_error
Definition logging.c:31
#define SGR_LOCUS_DEFAULT
Definition logging.c:39
#define SGR_ERROR_DEFAULT
Definition logging.c:36
static const char * sgr_warning
Definition logging.c:32
static const char * sgr_locus
Definition logging.c:34
static const char * progname
Definition logging.c:23
static char * argv0
Definition pg_ctl.c:94
char * strsep(char **stringp, const char *delim)
Definition strsep.c:49
const char * get_progname(const char *argv0)
Definition path.c:652
e
#define free(a)
const char * name

References __pg_log_level, argv0, fb(), free, get_progname(), name, PG_LOG_INFO, progname, sgr_error, SGR_ERROR_DEFAULT, sgr_locus, SGR_LOCUS_DEFAULT, sgr_note, SGR_NOTE_DEFAULT, sgr_warning, SGR_WARNING_DEFAULT, strsep(), token, and value.

Referenced by get_opts(), main(), main(), and regression_main().

◆ pg_logging_set_level()

void pg_logging_set_level ( enum pg_log_level  new_level)

Definition at line 178 of file logging.c.

179{
181}

References __pg_log_level, and fb().

Referenced by main(), and main().

◆ pg_logging_set_locus_callback()

void pg_logging_set_locus_callback ( void(*)(const char **filename, uint64 *lineno)  cb)

Definition at line 204 of file logging.c.

205{
207}
static void(* log_locus_callback)(const char **, uint64 *)
Definition logging.c:27

References log_locus_callback.

Referenced by main().

◆ pg_logging_set_logfile()

void pg_logging_set_logfile ( FILE logfile)

Definition at line 210 of file logging.c.

211{
213}
static FILE * log_logfile
Definition logging.c:29
static FILE * logfile
Definition pg_regress.c:128

References log_logfile, and logfile.

Referenced by main().

◆ pg_logging_set_pre_callback()

void pg_logging_set_pre_callback ( void(*)(void cb)

Definition at line 198 of file logging.c.

199{
200 log_pre_callback = cb;
201}
static void(* log_pre_callback)(void)
Definition logging.c:26

References log_pre_callback.

Referenced by main().

◆ pg_logging_unset_logfile()

void pg_logging_unset_logfile ( void  )

Definition at line 216 of file logging.c.

217{
219}

References fb(), and log_logfile.

Variable Documentation

◆ __pg_log_level