12 #error "This file is not expected to be compiled for backend code"
34 #define SGR_ERROR_DEFAULT "01;31"
35 #define SGR_WARNING_DEFAULT "01;35"
36 #define SGR_NOTE_DEFAULT "01;36"
37 #define SGR_LOCUS_DEFAULT "01"
39 #define ANSI_ESCAPE_FMT "\x1b[%sm"
40 #define ANSI_ESCAPE_RESET "\x1b[0m"
44 #ifndef ENABLE_VIRTUAL_TERMINAL_PROCESSING
45 #define ENABLE_VIRTUAL_TERMINAL_PROCESSING 0x0004
54 enable_vt_processing(
void)
57 HANDLE hOut = GetStdHandle(STD_ERROR_HANDLE);
60 if (hOut == INVALID_HANDLE_VALUE)
67 if (!GetConsoleMode(hOut, &dwMode))
69 if ((dwMode & ENABLE_VIRTUAL_TERMINAL_PROCESSING) != 0)
72 dwMode |= ENABLE_VIRTUAL_TERMINAL_PROCESSING;
73 if (!SetConsoleMode(hOut, dwMode))
85 const char *pg_color_env = getenv(
"PG_COLOR");
86 bool log_color =
false;
87 bool color_terminal = isatty(fileno(stderr));
96 color_terminal = enable_vt_processing();
100 setvbuf(stderr, NULL, _IONBF, 0);
107 if (strcmp(pg_color_env,
"always") == 0 ||
108 (strcmp(pg_color_env,
"auto") == 0 && color_terminal))
114 const char *pg_colors_env = getenv(
"PG_COLORS");
118 char *colors = strdup(pg_colors_env);
127 char *
e = strchr(
token,
'=');
138 if (strcmp(
name,
"error") == 0)
140 if (strcmp(
name,
"warning") == 0)
142 if (strcmp(
name,
"note") == 0)
144 if (strcmp(
name,
"locus") == 0)
209 const char *pg_restrict
fmt,...)
220 const char *pg_restrict
fmt, va_list ap)
222 int save_errno = errno;
331 if (required_len >= 2 &&
buf[required_len - 2] ==
'\n')
332 buf[required_len - 2] =
'\0';
#define Assert(condition)
void * pg_malloc_extended(size_t size, int flags)
#define MCXT_ALLOC_NO_OOM
static void const char * fmt
static void const char fflush(stdout)
vfprintf(stderr, fmt, args)
void pg_logging_increase_verbosity(void)
#define SGR_WARNING_DEFAULT
static const char * sgr_note
static const char * sgr_error
#define SGR_LOCUS_DEFAULT
void pg_logging_init(const char *argv0)
#define SGR_ERROR_DEFAULT
void pg_logging_set_locus_callback(void(*cb)(const char **filename, uint64 *lineno))
static const char * sgr_warning
static void(* log_pre_callback)(void)
static void(* log_locus_callback)(const char **, uint64 *)
static const char * sgr_locus
void pg_logging_config(int new_flags)
void pg_logging_set_level(enum pg_log_level new_level)
void pg_log_generic_v(enum pg_log_level level, enum pg_log_part part, const char *pg_restrict fmt, va_list ap)
void pg_logging_set_pre_callback(void(*cb)(void))
static const char * progname
enum pg_log_level __pg_log_level
#define ANSI_ESCAPE_RESET
void pg_log_generic(enum pg_log_level level, enum pg_log_part part, const char *pg_restrict fmt,...)
#define PG_LOG_FLAG_TERSE
const char * get_progname(const char *argv0)
char * strsep(char **stringp, const char *delim)