Improve logging output

This commit is contained in:
Ian Barwick
2017-04-25 08:22:58 +09:00
parent ef5c6b37a4
commit 885bc122df
5 changed files with 23 additions and 6 deletions

View File

@@ -72,6 +72,8 @@ _establish_db_connection(const char *conninfo, const bool exit_on_error, const b
log_error(_("connection to database failed: %s"),
PQerrorMessage(conn));
}
log_detail(_("attempted to connect using:\n %s"),
connection_string);
}
if (exit_on_error)

16
log.c
View File

@@ -55,7 +55,7 @@ _stderr_log_with_level(const char *level_name, int level, const char *fmt, va_li
/*
* Store the requested level so that if there's a subsequent
* log_hint(), we can suppress that if appropriate.
* log_hint() or log_detail(), we can suppress that if appropriate.
*/
last_log_level = level;
@@ -97,6 +97,20 @@ log_hint(const char *fmt, ...)
}
void
log_detail(const char *fmt, ...)
{
va_list ap;
if (terse_logging == false)
{
va_start(ap, fmt);
_stderr_log_with_level("DETAIL", last_log_level, fmt, ap);
va_end(ap);
}
}
void
log_verbose(int level, const char *fmt, ...)
{

2
log.h
View File

@@ -114,6 +114,8 @@ bool logger_shutdown(void);
void logger_set_verbose(void);
void logger_set_terse(void);
void log_detail(const char *fmt, ...)
__attribute__((format(PG_PRINTF_ATTRIBUTE, 1, 2)));
void log_hint(const char *fmt, ...)
__attribute__((format(PG_PRINTF_ATTRIBUTE, 1, 2)));
void log_verbose(int level, const char *fmt, ...)

View File

@@ -446,9 +446,9 @@ do_master_register(void)
log_info(_("connecting to master database..."));
// XXX if con fails, have this print offending conninfo!
conn = establish_db_connection(config_file_options.conninfo, true);
log_verbose(LOG_INFO, _("connected to server, checking its state"));
/* verify that node is running a supported server version */
check_server_version(conn, "master", true, NULL);
@@ -575,10 +575,9 @@ do_master_register(void)
commit_transaction(conn);
PQfinish(conn);
log_notice(_("master node %s with id %i (conninfo: %s)"),
record_found ? "updated" : "registered",
log_notice(_("master node record (id: %i) %s"),
config_file_options.node_id,
config_file_options.conninfo);
record_found ? "updated" : "registered");
return;
}

View File

@@ -6,5 +6,5 @@ node=1
node_id=1
node_name='node1'
use_replication_slots = true
conninfo = 'host=127.0.0.1 dbname=repmgr user=repmgr port=5501'
conninfo = 'host=127.0.0.1 dbname=repmgr user=repmgr port=5501 connect_timeout=2'
loglevel = 'DEBUG'