PostgreSQL Source Code  git master
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_fatal(...)
 
#define pg_log_error(...)
 
#define pg_log_warning(...)
 
#define pg_log_info(...)
 
#define pg_log_debug(...)
 

Enumerations

enum  pg_log_level {
  PG_LOG_NOTSET = 0 , PG_LOG_DEBUG , PG_LOG_INFO , PG_LOG_WARNING ,
  PG_LOG_ERROR , PG_LOG_FATAL , PG_LOG_OFF
}
 

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, const char *pg_restrict fmt,...) pg_attribute_printf(2
 
void void pg_log_generic_v (enum pg_log_level level, const char *pg_restrict fmt, va_list ap) pg_attribute_printf(2
 

Variables

enum pg_log_level __pg_log_level
 

Macro Definition Documentation

◆ pg_log_debug

#define pg_log_debug (   ...)
Value:
do { \
} while(0)
#define unlikely(x)
Definition: c.h:273
void pg_log_generic(enum pg_log_level level, const char *pg_restrict fmt,...) pg_attribute_printf(2
@ PG_LOG_DEBUG
Definition: logging.h:26
enum pg_log_level __pg_log_level
Definition: logging.c:21

Definition at line 92 of file logging.h.

◆ pg_log_error

#define pg_log_error (   ...)
Value:
do { \
} while(0)
#define likely(x)
Definition: c.h:272
@ PG_LOG_ERROR
Definition: logging.h:43

Definition at line 80 of file logging.h.

◆ pg_log_fatal

#define pg_log_fatal (   ...)
Value:
do { \
} while(0)
@ PG_LOG_FATAL
Definition: logging.h:50

Definition at line 76 of file logging.h.

◆ PG_LOG_FLAG_TERSE

#define PG_LOG_FLAG_TERSE   1

Definition at line 64 of file logging.h.

◆ pg_log_info

#define pg_log_info (   ...)
Value:
do { \
} while(0)
@ PG_LOG_INFO
Definition: logging.h:33

Definition at line 88 of file logging.h.

◆ pg_log_warning

#define pg_log_warning (   ...)
Value:
do { \
} while(0)
@ PG_LOG_WARNING
Definition: logging.h:38

Definition at line 84 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_FATAL 
PG_LOG_OFF 

Definition at line 16 of file logging.h.

17 {
18  /*
19  * Not initialized yet
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  * 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  */
55  PG_LOG_OFF,
56 };
@ PG_LOG_NOTSET
Definition: logging.h:21
@ PG_LOG_OFF
Definition: logging.h:55

Function Documentation

◆ pg_log_generic()

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

◆ pg_log_generic_v()

void void pg_log_generic_v ( enum pg_log_level  level,
const char *pg_restrict  fmt,
va_list  ap 
)

◆ pg_logging_config()

void pg_logging_config ( int  new_flags)

Definition at line 155 of file logging.c.

156 {
157  log_flags = new_flags;
158 }
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 174 of file logging.c.

175 {
176  /*
177  * The enum values are chosen such that we have to decrease __pg_log_level
178  * in order to become more verbose.
179  */
180  if (__pg_log_level > PG_LOG_NOTSET + 1)
181  __pg_log_level--;
182 }
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 81 of file logging.c.

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

References __pg_log_level, argv0, free, get_progname(), name, PG_LOG_INFO, progname, sgr_error, SGR_ERROR_DEFAULT, sgr_locus, SGR_LOCUS_DEFAULT, sgr_warning, SGR_WARNING_DEFAULT, 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 165 of file logging.c.

166 {
167  __pg_log_level = new_level;
168 }

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 191 of file logging.c.

192 {
193  log_locus_callback = cb;
194 }
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 185 of file logging.c.

186 {
187  log_pre_callback = cb;
188 }
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