diff --git a/check_dir.c b/check_dir.c index e0d0953f..ccf94abe 100644 --- a/check_dir.c +++ b/check_dir.c @@ -29,7 +29,7 @@ #include "check_dir.h" #include "strutil.h" - +#include "log.h" static int mkdir_p(char *path, mode_t omode); @@ -99,7 +99,7 @@ create_directory(char *dir) if (mkdir_p(dir, 0700) == 0) return true; - fprintf(stderr, _("Could not create directory \"%s\": %s\n"), + log_err(_("Could not create directory \"%s\": %s\n"), dir, strerror(errno)); return false; diff --git a/dbutils.c b/dbutils.c index 18fc166d..37b938d1 100644 --- a/dbutils.c +++ b/dbutils.c @@ -18,8 +18,8 @@ */ #include "repmgr.h" - #include "strutil.h" +#include "log.h" PGconn * establishDBConnection(const char *conninfo, const bool exit_on_error) @@ -30,7 +30,7 @@ establishDBConnection(const char *conninfo, const bool exit_on_error) /* Check to see that the backend connection was successfully made */ if ((PQstatus(conn) != CONNECTION_OK)) { - fprintf(stderr, "Connection to database failed: %s", + log_err(_("Connection to database failed: %s\n"), PQerrorMessage(conn)); if (exit_on_error) @@ -54,7 +54,8 @@ is_standby(PGconn *conn) if (PQresultStatus(res) != PGRES_TUPLES_OK) { - fprintf(stderr, "Can't query server mode: %s", PQerrorMessage(conn)); + log_err(_("Can't query server mode: %s"), + PQerrorMessage(conn)); PQclear(res); PQfinish(conn); exit(ERR_DB_QUERY); @@ -90,7 +91,8 @@ pg_version(PGconn *conn, char* major_version) if (PQresultStatus(res) != PGRES_TUPLES_OK) { - fprintf(stderr, "PQexec failed: %s", PQerrorMessage(conn)); + log_err(_("Version check PQexec failed: %s"), + PQerrorMessage(conn)); PQclear(res); PQfinish(conn); exit(ERR_DB_QUERY); @@ -128,7 +130,8 @@ guc_setted(PGconn *conn, const char *parameter, const char *op, res = PQexec(conn, sqlquery); if (PQresultStatus(res) != PGRES_TUPLES_OK) { - fprintf(stderr, "PQexec failed: %s", PQerrorMessage(conn)); + log_err(_("GUC setting check PQexec failed: %s"), + PQerrorMessage(conn)); PQclear(res); PQfinish(conn); exit(ERR_DB_QUERY); @@ -159,7 +162,8 @@ get_cluster_size(PGconn *conn) res = PQexec(conn, sqlquery); if (PQresultStatus(res) != PGRES_TUPLES_OK) { - fprintf(stderr, "PQexec failed: %s", PQerrorMessage(conn)); + log_err(_("Get cluster size PQexec failed: %s"), + PQerrorMessage(conn)); PQclear(res); PQfinish(conn); exit(ERR_DB_QUERY); @@ -221,7 +225,7 @@ getMasterConnection(PGconn *standby_conn, int id, char *cluster, res1 = PQexec(standby_conn, sqlquery); if (PQresultStatus(res1) != PGRES_TUPLES_OK) { - fprintf(stderr, "Can't get nodes info: %s\n", + log_err(_("Can't get nodes info: %s\n"), PQerrorMessage(standby_conn)); PQclear(res1); PQfinish(standby_conn); @@ -247,7 +251,7 @@ getMasterConnection(PGconn *standby_conn, int id, char *cluster, if (PQresultStatus(res2) != PGRES_TUPLES_OK) { - fprintf(stderr, "Can't get recovery state from this node: %s\n", + log_err(_("Can't get recovery state from this node: %s\n"), PQerrorMessage(master_conn)); PQclear(res2); PQfinish(master_conn); diff --git a/log.h b/log.h index 16df5ecd..dc9d7843 100644 --- a/log.h +++ b/log.h @@ -20,6 +20,8 @@ #ifndef _REPMGR_LOG_H_ #define _REPMGR_LOG_H_ +#include "repmgr.h" + #define REPMGR_SYSLOG 1 #define REPMGR_STDERR 2 diff --git a/repmgr.c b/repmgr.c index f12770ba..e058bad4 100644 --- a/repmgr.c +++ b/repmgr.c @@ -676,7 +676,6 @@ do_standby_clone(void) case 0: /* dest_dir not there, must create it */ log_info(_("creating directory %s ...\n"), runtime_options.dest_dir); - fflush(stdout); if (!create_directory(runtime_options.dest_dir)) { @@ -687,9 +686,8 @@ do_standby_clone(void) break; case 1: /* Present but empty, fix permissions and use it */ - log_info(_("fixing permissions on existing directory %s ...\n"), + log_info(_("checking and correcting permissions on existing directory %s ...\n"), runtime_options.dest_dir); - fflush(stdout); if (!set_directory_permissions(runtime_options.dest_dir)) { @@ -808,9 +806,7 @@ do_standby_clone(void) { case 0: /* tblspc_dir not there, must create it */ - if (runtime_options.verbose) - printf(_("creating directory \"%s\"... "), tblspc_dir); - fflush(stdout); + log_info(_("creating directory \"%s\"... "), tblspc_dir); if (!create_directory(tblspc_dir)) { @@ -823,10 +819,8 @@ do_standby_clone(void) break; case 1: /* Present but empty, fix permissions and use it */ - if (runtime_options.verbose) - printf(_("fixing permissions on existing directory \"%s\"... "), - tblspc_dir); - fflush(stdout); + log_info(_("fixing permissions on existing directory \"%s\"... "), + tblspc_dir); if (!set_directory_permissions(tblspc_dir)) { @@ -841,10 +835,8 @@ do_standby_clone(void) /* Present and not empty */ if (!runtime_options.force) { - fprintf( - stderr, - _("%s: directory \"%s\" exists but is not empty\n"), - progname, tblspc_dir); + log_err(_("%s: directory \"%s\" exists but is not empty\n"), + progname, tblspc_dir); PQclear(res); PQfinish(conn); exit(ERR_BAD_CONFIG); diff --git a/strutil.c b/strutil.c index 641b234f..6af395e6 100644 --- a/strutil.c +++ b/strutil.c @@ -22,6 +22,7 @@ #include #include +#include "log.h" #include "strutil.h" static int xvsnprintf(char *str, size_t size, const char *format, va_list ap); @@ -36,7 +37,8 @@ xvsnprintf(char *str, size_t size, const char *format, va_list ap) if (retval >= size) { - fprintf(stderr, "Buffer not large enough to format entire string\n"); + log_err(_("Buffer of size not large enough to format entire string '%s'\n"), + str); exit(ERR_STR_OVERFLOW); }