PostgreSQL Source Code  git master
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
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(...)
 

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_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 { \
pg_log_generic(PG_LOG_ERROR, PG_LOG_PRIMARY, __VA_ARGS__); \
exit(1); \
} while(0)
@ PG_LOG_PRIMARY
Definition: logging.h:67
@ PG_LOG_ERROR
Definition: logging.h:43

Definition at line 151 of file logging.h.

◆ pg_log_debug

#define pg_log_debug (   ...)
Value:
do { \
pg_log_generic(PG_LOG_DEBUG, PG_LOG_PRIMARY, __VA_ARGS__); \
} while(0)
#define unlikely(x)
Definition: c.h:326
@ PG_LOG_DEBUG
Definition: logging.h:26
enum pg_log_level __pg_log_level
Definition: logging.c:21

Definition at line 133 of file logging.h.

◆ pg_log_debug_detail

#define pg_log_debug_detail (   ...)
Value:
do { \
pg_log_generic(PG_LOG_DEBUG, PG_LOG_DETAIL, __VA_ARGS__); \
} while(0)
@ PG_LOG_DETAIL
Definition: logging.h:73

Definition at line 138 of file logging.h.

◆ pg_log_debug_hint

#define pg_log_debug_hint (   ...)
Value:
do { \
pg_log_generic(PG_LOG_DEBUG, PG_LOG_HINT, __VA_ARGS__); \
} while(0)
@ PG_LOG_HINT
Definition: logging.h:79

Definition at line 143 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 106 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 109 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 112 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 124 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 127 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 130 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 115 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 118 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 121 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  */
48  PG_LOG_OFF,
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 166 of file logging.c.

167 {
168  log_flags = new_flags;
169 }
static int log_flags
Definition: logging.c:24

References log_flags.

Referenced by main(), and process_file().

◆ pg_logging_increase_verbosity()

void pg_logging_increase_verbosity ( void  )

Definition at line 185 of file logging.c.

186 {
187  /*
188  * The enum values are chosen such that we have to decrease __pg_log_level
189  * in order to become more verbose.
190  */
191  if (__pg_log_level > PG_LOG_NOTSET + 1)
192  __pg_log_level--;
193 }
enum pg_log_level __pg_log_level
Definition: logging.c:21

References __pg_log_level, and PG_LOG_NOTSET.

Referenced by main().

◆ pg_logging_init()

void pg_logging_init ( const char *  argv0)

Definition at line 83 of file logging.c.

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

References __pg_log_level, argv0, 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(), and regression_main().

◆ pg_logging_set_level()

void pg_logging_set_level ( enum pg_log_level  new_level)

Definition at line 176 of file logging.c.

177 {
178  __pg_log_level = new_level;
179 }

References __pg_log_level.

Referenced by main().

◆ pg_logging_set_locus_callback()

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

Definition at line 202 of file logging.c.

203 {
204  log_locus_callback = cb;
205 }
static void(* log_locus_callback)(const char **, uint64 *)
Definition: logging.c:27

References log_locus_callback.

Referenced by main().

◆ pg_logging_set_pre_callback()

void pg_logging_set_pre_callback ( void(*)(void)  cb)

Definition at line 196 of file logging.c.

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

References log_pre_callback.

Referenced by main().

Variable Documentation

◆ __pg_log_level

enum pg_log_level __pg_log_level
extern