PostgreSQL Source Code  git master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
logging.c File Reference
#include "postgres_fe.h"
#include <unistd.h>
#include <time.h>
#include "pg_rewind.h"
#include "logging.h"
#include "pgtime.h"
Include dependency graph for logging.c:

Go to the source code of this file.

Macros

#define QUERY_ALLOC   8192
 
#define MESSAGE_WIDTH   60
 

Functions

static pg_attribute_printf (2, 0)
 
void pg_log (eLogType type, const char *fmt,...)
 
void pg_fatal (const char *fmt,...)
 
void progress_report (bool force)
 

Variables

uint64 fetch_size
 
uint64 fetch_done
 
static pg_time_t last_progress_report = 0
 

Macro Definition Documentation

#define MESSAGE_WIDTH   60

Definition at line 28 of file logging.c.

Referenced by pg_log_v(), and prep_status().

#define QUERY_ALLOC   8192

Function Documentation

static pg_attribute_printf ( ,
 
)
static

Definition at line 31 of file logging.c.

References _, debug, PG_DEBUG, PG_FATAL, PG_PROGRESS, PG_WARNING, QUERY_ALLOC, showprogress, and vsnprintf().

34 {
35  char message[QUERY_ALLOC];
36 
37  vsnprintf(message, sizeof(message), _(fmt), ap);
38 
39  switch (type)
40  {
41  case PG_DEBUG:
42  if (debug)
43  printf("%s", message);
44  break;
45 
46  case PG_PROGRESS:
47  if (showprogress)
48  printf("%s", message);
49  break;
50 
51  case PG_WARNING:
52  printf("%s", message);
53  break;
54 
55  case PG_FATAL:
56  printf("\n%s", message);
57  printf("%s", _("Failure, exiting\n"));
58  exit(1);
59  break;
60 
61  default:
62  break;
63  }
64  fflush(stdout);
65 }
#define QUERY_ALLOC
Definition: logging.c:26
int int vsnprintf(char *str, size_t count, const char *fmt, va_list args)
bool debug
Definition: pg_standby.c:46
static bool showprogress
Definition: pg_basebackup.c:83
#define _(x)
Definition: elog.c:84
void pg_fatal ( const char *  fmt,
  ... 
)

Definition at line 83 of file logging.c.

References generate_unaccent_rules::args, PG_FATAL, and pg_log_v().

Referenced by adjust_data_dir(), check_cluster_compatibility(), check_cluster_versions(), check_control_data(), check_for_isn_and_int8_passing_mismatch(), check_for_jsonb_9_4_usage(), check_for_pg_role_prefix(), check_for_prepared_transactions(), check_for_reg_data_type_usage(), check_hard_link(), check_is_install_user(), check_loadable_libraries(), check_locale_and_encoding(), check_new_cluster_is_empty(), check_pghost_envvar(), check_proper_datallowconn(), check_required_directory(), checkControlFile(), close_target_file(), copy_file_range(), copyFile(), create_script_for_cluster_analyze(), create_script_for_old_cluster_deletion(), create_target(), create_target_dir(), create_target_symlink(), createBackupLabel(), digestControlFile(), disable_old_cluster(), exec_prog(), extractPageInfo(), extractPageMap(), fetch_file_range(), findCommonAncestorTimeline(), findLastCheckpoint(), gen_db_file_maps(), get_bin_version(), get_canonical_locale_name(), get_control_data(), get_loadable_libraries(), get_major_server_version(), get_sock_dir(), getTimelineHistory(), init_tablespaces(), libpq_executeFileMap(), libpqConnect(), libpqGetCurrentXlogInsertLocation(), libpqGetFile(), libpqProcessFileList(), linkFile(), new_9_0_populate_pg_largeobject_metadata(), old_9_3_check_for_line_data_type_usage(), old_9_6_check_for_unknown_data_type_usage(), open_target_file(), parallel_exec_prog(), parallel_transfer_all_new_dbs(), parseCommandLine(), pid_lock_file_exists(), process_block_change(), process_source_file(), process_target_file(), readOneRecord(), reap_child(), receiveFileChunks(), recurse_dir(), remove_new_subdir(), remove_target_dir(), remove_target_file(), remove_target_symlink(), rewriteVisibilityMap(), run_simple_query(), sanityChecks(), setup(), slurpFile(), start_postmaster(), syncTargetDirectory(), transfer_all_new_dbs(), transfer_relfile(), truncate_target_file(), validate_exec(), verify_directories(), and write_target_range().

84 {
85  va_list args;
86 
87  va_start(args, fmt);
88  pg_log_v(PG_FATAL, fmt, args);
89  va_end(args);
90  /* should not get here, pg_log_v() exited already */
91  exit(1);
92 }
static void pg_log_v(eLogType type, const char *fmt, va_list ap) pg_attribute_printf(2
Definition: util.c:88
void progress_report ( bool  force)

Definition at line 102 of file logging.c.

References fetch_done, fetch_size, INT64_FORMAT, last_progress_report, now(), NULL, pg_log(), PG_PROGRESS, showprogress, and snprintf().

103 {
104  int percent;
105  char fetch_done_str[32];
106  char fetch_size_str[32];
107  pg_time_t now;
108 
109  if (!showprogress)
110  return;
111 
112  now = time(NULL);
113  if (now == last_progress_report && !force)
114  return; /* Max once per second */
115 
117  percent = fetch_size ? (int) ((fetch_done) * 100 / fetch_size) : 0;
118 
119  /*
120  * Avoid overflowing past 100% or the full size. This may make the total
121  * size number change as we approach the end of the backup (the estimate
122  * will always be wrong if WAL is included), but that's better than having
123  * the done column be bigger than the total.
124  */
125  if (percent > 100)
126  percent = 100;
127  if (fetch_done > fetch_size)
129 
130  /*
131  * Separate step to keep platform-dependent format code out of
132  * translatable strings. And we only test for INT64_FORMAT availability
133  * in snprintf, not fprintf.
134  */
135  snprintf(fetch_done_str, sizeof(fetch_done_str), INT64_FORMAT,
136  fetch_done / 1024);
137  snprintf(fetch_size_str, sizeof(fetch_size_str), INT64_FORMAT,
138  fetch_size / 1024);
139 
140  pg_log(PG_PROGRESS, "%*s/%s kB (%d%%) copied",
141  (int) strlen(fetch_size_str), fetch_done_str, fetch_size_str,
142  percent);
143  printf("\r");
144 }
int64 pg_time_t
Definition: pgtime.h:23
uint64 fetch_done
Definition: logging.c:22
uint64 fetch_size
Definition: logging.c:21
int snprintf(char *str, size_t count, const char *fmt,...) pg_attribute_printf(3
void pg_log(eLogType type, const char *fmt,...)
Definition: logging.c:69
static pg_time_t last_progress_report
Definition: logging.c:24
static bool showprogress
Definition: pg_basebackup.c:83
#define NULL
Definition: c.h:229
#define INT64_FORMAT
Definition: c.h:315
Datum now(PG_FUNCTION_ARGS)
Definition: timestamp.c:1534

Variable Documentation

uint64 fetch_done

Definition at line 22 of file logging.c.

Referenced by main(), progress_report(), and write_target_range().

uint64 fetch_size
pg_time_t last_progress_report = 0
static

Definition at line 24 of file logging.c.

Referenced by progress_report().