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_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 (   ...)

◆ pg_log_error

#define pg_log_error (   ...)
Value:
do { \
} while(0)
#define likely(x)
Definition: c.h:207
enum pg_log_level __pg_log_level
Definition: logging.c:16
void pg_log_generic(enum pg_log_level level, const char *pg_restrict fmt,...) pg_attribute_printf(2

Definition at line 79 of file logging.h.

Referenced by _check_database_version(), AcceptResult(), appendQualifiedRelation(), BaseBackup(), bootstrap_template1(), check_authmethod_valid(), check_input(), check_locale_encoding(), check_locale_name(), check_need_password(), CheckCopyStreamStop(), CheckDataVersion(), CheckServerVersionForStreaming(), cleanup_directories_atexit(), CleanupPriorWALFiles(), close_destination_dir(), close_walfile(), cluster_one_database(), connectDatabase(), CopyStreamPoll(), CopyStreamReceive(), create_data_directory(), create_xlog_or_symlink(), CreateReplicationSlot(), describeAccessMethods(), describeFunctions(), describeOneTableDetails(), describePublications(), describeSubscriptions(), describeTableDetails(), die_on_query_failure(), do_connect(), do_copy(), do_edit(), do_pset(), do_shell(), do_watch(), DropReplicationSlot(), dumpDatabases(), dumpPolicy(), dumpRule(), dumpSequence(), dumpSequenceData(), dumpTableData_copy(), dumpTablespaces(), dumpTrigger(), durable_rename(), editFile(), ensureCleanShutdown(), escape_quotes(), exec_command_cd(), exec_command_edit(), exec_command_ef_ev(), exec_command_elif(), exec_command_else(), exec_command_encoding(), exec_command_endif(), exec_command_errverbose(), exec_command_include(), exec_command_lo(), exec_command_password(), exec_command_prompt(), exec_command_setenv(), exec_command_sf_sv(), exec_command_unset(), exec_command_write(), executeCommand(), executeQuery(), FindEndOfXLOG(), findParentsByOid(), FindStreamingStart(), fsync_fname(), fsync_pgdata(), GenerateRecoveryConfig(), get_create_object_cmd(), get_destination_dir(), get_encoding_id(), get_id(), get_restricted_token(), get_su_pwd(), GetConnection(), gets_fromFile(), getTableAttrs(), handle_args(), handleCopyOut(), HandleCopyStream(), HandleEndOfCopyStream(), HandleSlashCmds(), indexOfColumn(), init_parallel_dump_utils(), Initialize(), initialize_data_directory(), initializeInput(), KillExistingArchiveStatus(), KillExistingXLOG(), listCollations(), listDbRoleSettings(), listDefaultACLs(), listExtensionContents(), listExtensions(), listForeignDataWrappers(), listForeignServers(), listForeignTables(), listPartitionedTables(), listPublications(), listTables(), listTSConfigs(), listTSConfigsVerbose(), listTSDictionaries(), listTSParsers(), listTSParsersVerbose(), listTSTemplates(), listUserMappings(), LogStreamerMain(), main(), MainLoop(), mark_file_as_archived(), minimal_error_message(), open_walfile(), openQueryOutputFile(), parse_max_rate(), parse_slash_copy(), parseOidArray(), ParseVariableBool(), ParseVariableNum(), popen_check(), printCrosstab(), printHistory(), printPsetInfo(), PrintQueryResults(), PrintResultsInCrosstab(), process_file(), ProcessKeepaliveMsg(), processQueryResult(), ProcessResult(), ProcessXLogDataMsg(), psql_get_variable(), PSQLexec(), PSQLexecWatch(), PsqlVarEnumError(), reached_end_position(), ReadControlFile(), ReadEndOfStreamingResult(), readfile(), readMessageFromPipe(), ReceiveAndUnpackTarFile(), ReceiveCopyData(), ReceiveTarAndUnpackCopyChunk(), ReceiveTarFile(), ReceiveXlogStream(), reindex_one_database(), RetrieveDataDirCreatePerm(), RetrieveWalSegSize(), rewind_parseTimeLineHistory(), run_reindex_command(), run_vacuum_command(), RunIdentifySystem(), scan_directory(), scan_file(), sendFeedback(), SendQuery(), set_dump_section(), set_null_conf(), setup_bin_paths(), setup_config(), setup_locale_encoding(), setup_pgdata(), SetVariable(), SetWALFileNameForCleanup(), SimpleXLogPageRead(), sql_conn(), sql_exec(), start_lo_xact(), StartLogStreamer(), StoreQueryTuple(), StreamLogicalLog(), strip_lineno_from_objdesc(), tablespace_list_append(), vacuum_one_database(), vacuumlo(), verify_dir_is_empty_or_create(), walkdir(), write_version_file(), WriteEmptyXLOG(), writefile(), WriteRecoveryConfig(), writeTarData(), and writeTimeLineHistoryFile().

◆ pg_log_fatal

#define pg_log_fatal (   ...)
Value:
do { \
} while(0)
#define likely(x)
Definition: c.h:207
enum pg_log_level __pg_log_level
Definition: logging.c:16
void pg_log_generic(enum pg_log_level level, const char *pg_restrict fmt,...) pg_attribute_printf(2

Definition at line 75 of file logging.h.

Referenced by CheckConnection(), get_controlfile(), HandleCopyStream(), main(), on_exit_nicely(), open_walfile(), OutputFsync(), ParallelSlotsSetup(), parse_psql_options(), process_psqlrc(), ProcessKeepaliveMsg(), update_controlfile(), and usage().

◆ PG_LOG_FLAG_TERSE

#define PG_LOG_FLAG_TERSE   1

Definition at line 64 of file logging.h.

Referenced by main(), pg_log_generic_v(), and process_file().

◆ pg_log_info

#define pg_log_info (   ...)
Value:
do { \
} while(0)
#define likely(x)
Definition: c.h:207
enum pg_log_level __pg_log_level
Definition: logging.c:16
void pg_log_generic(enum pg_log_level level, const char *pg_restrict fmt,...) pg_attribute_printf(2

Definition at line 87 of file logging.h.

Referenced by _connectDB(), _disableTriggersIfNecessary(), _enableTriggersIfNecessary(), _LoadBlobs(), AcceptResult(), BaseBackup(), CheckDataVersion(), cleanup_directories_atexit(), close_walfile(), DescribeQuery(), describeTablespaces(), do_connect(), do_lo_export(), do_lo_import(), do_lo_unlink(), dumpBlobs(), dumpDatabase(), dumpDatabases(), dumpEncoding(), dumpSearchPath(), dumpStdStrings(), dumpTableData_copy(), EndRestoreBlobs(), ensureCleanShutdown(), exec_command_password(), executeCommand(), executeQuery(), getBlobs(), getConstraints(), getDependencies(), getIndexes(), getPolicies(), getPublicationTables(), getSchemaData(), getTableAttrs(), getTriggers(), handleCopyIn(), handleCopyOut(), HandleSlashCmds(), inhibit_data_for_failed_table(), libpqConnect(), main(), mark_dump_job_done(), mark_restore_job_done(), NoticeProcessor(), prepareToTerminate(), psql_get_variable(), ReadControlFile(), restore_toc_entries_parallel(), restore_toc_entries_postfork(), restore_toc_entries_prefork(), restore_toc_entry(), RestoreArchive(), runPgDump(), scan_file(), sendFeedback(), SendQuery(), setup_text_search(), StartLogStreamer(), StartRestoreBlob(), stop_streaming(), StreamLog(), and StreamLogicalLog().

◆ pg_log_warning

#define pg_log_warning (   ...)
Value:
do { \
} while(0)
#define likely(x)
Definition: c.h:207
enum pg_log_level __pg_log_level
Definition: logging.c:16
void pg_log_generic(enum pg_log_level level, const char *pg_restrict fmt,...) pg_attribute_printf(2

Definition at line 83 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 };

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

References log_flags.

Referenced by main(), and process_file().

103 {
104  log_flags = new_flags;
105 }
static int log_flags
Definition: logging.c:19

◆ pg_logging_init()

void pg_logging_init ( const char *  argv0)

Definition at line 39 of file logging.c.

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

40 {
41  const char *pg_color_env = getenv("PG_COLOR");
42  bool log_color = false;
43 
44  /* usually the default, but not on Windows */
45  setvbuf(stderr, NULL, _IONBF, 0);
46 
49 
50  if (pg_color_env)
51  {
52  if (strcmp(pg_color_env, "always") == 0 ||
53  (strcmp(pg_color_env, "auto") == 0 && isatty(fileno(stderr))))
54  log_color = true;
55  }
56 
57  if (log_color)
58  {
59  const char *pg_colors_env = getenv("PG_COLORS");
60 
61  if (pg_colors_env)
62  {
63  char *colors = strdup(pg_colors_env);
64 
65  if (colors)
66  {
67  for (char *token = strtok(colors, ":"); token; token = strtok(NULL, ":"))
68  {
69  char *e = strchr(token, '=');
70 
71  if (e)
72  {
73  char *name;
74  char *value;
75 
76  *e = '\0';
77  name = token;
78  value = e + 1;
79 
80  if (strcmp(name, "error") == 0)
81  sgr_error = strdup(value);
82  if (strcmp(name, "warning") == 0)
83  sgr_warning = strdup(value);
84  if (strcmp(name, "locus") == 0)
85  sgr_locus = strdup(value);
86  }
87  }
88 
89  free(colors);
90  }
91  }
92  else
93  {
97  }
98  }
99 }
static char * argv0
Definition: pg_ctl.c:97
const char * get_progname(const char *argv0)
Definition: path.c:453
static struct @145 value
#define SGR_LOCUS_DEFAULT
Definition: logging.c:30
static const char * sgr_error
Definition: logging.c:24
static const char * sgr_warning
Definition: logging.c:25
enum pg_log_level __pg_log_level
Definition: logging.c:16
static const char * progname
Definition: logging.c:18
#define free(a)
Definition: header.h:65
#define SGR_ERROR_DEFAULT
Definition: logging.c:28
const char * name
Definition: encode.c:521
e
Definition: preproc-init.c:82
static const char * sgr_locus
Definition: logging.c:26
#define SGR_WARNING_DEFAULT
Definition: logging.c:29

◆ pg_logging_set_level()

void pg_logging_set_level ( enum pg_log_level  new_level)

Definition at line 108 of file logging.c.

References __pg_log_level.

Referenced by main().

109 {
110  __pg_log_level = new_level;
111 }
enum pg_log_level __pg_log_level
Definition: logging.c:16

◆ pg_logging_set_locus_callback()

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

Definition at line 120 of file logging.c.

References log_locus_callback.

Referenced by main().

121 {
122  log_locus_callback = cb;
123 }
static void(* log_locus_callback)(const char **, uint64 *)
Definition: logging.c:22

◆ pg_logging_set_pre_callback()

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

Definition at line 114 of file logging.c.

References log_pre_callback.

Referenced by main().

115 {
116  log_pre_callback = cb;
117 }
static void(* log_pre_callback)(void)
Definition: logging.c:21

Variable Documentation

◆ __pg_log_level

enum pg_log_level __pg_log_level

Definition at line 16 of file logging.c.

Referenced by pg_logging_init(), and pg_logging_set_level().