mirror of
https://github.com/EnterpriseDB/repmgr.git
synced 2026-03-23 07:06:30 +00:00
Convert more uses of fprintf to use logger
This commit is contained in:
@@ -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;
|
||||
|
||||
20
dbutils.c
20
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);
|
||||
|
||||
2
log.h
2
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
|
||||
|
||||
|
||||
20
repmgr.c
20
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);
|
||||
|
||||
@@ -22,6 +22,7 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#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);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user