Convert more uses of fprintf to use logger

This commit is contained in:
Greg Smith
2011-02-23 05:59:09 -05:00
parent 3b2203c38c
commit 18ef5b3cf3
5 changed files with 25 additions and 25 deletions

View File

@@ -29,7 +29,7 @@
#include "check_dir.h" #include "check_dir.h"
#include "strutil.h" #include "strutil.h"
#include "log.h"
static int mkdir_p(char *path, mode_t omode); static int mkdir_p(char *path, mode_t omode);
@@ -99,7 +99,7 @@ create_directory(char *dir)
if (mkdir_p(dir, 0700) == 0) if (mkdir_p(dir, 0700) == 0)
return true; return true;
fprintf(stderr, _("Could not create directory \"%s\": %s\n"), log_err(_("Could not create directory \"%s\": %s\n"),
dir, strerror(errno)); dir, strerror(errno));
return false; return false;

View File

@@ -18,8 +18,8 @@
*/ */
#include "repmgr.h" #include "repmgr.h"
#include "strutil.h" #include "strutil.h"
#include "log.h"
PGconn * PGconn *
establishDBConnection(const char *conninfo, const bool exit_on_error) 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 */ /* Check to see that the backend connection was successfully made */
if ((PQstatus(conn) != CONNECTION_OK)) if ((PQstatus(conn) != CONNECTION_OK))
{ {
fprintf(stderr, "Connection to database failed: %s", log_err(_("Connection to database failed: %s\n"),
PQerrorMessage(conn)); PQerrorMessage(conn));
if (exit_on_error) if (exit_on_error)
@@ -54,7 +54,8 @@ is_standby(PGconn *conn)
if (PQresultStatus(res) != PGRES_TUPLES_OK) 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); PQclear(res);
PQfinish(conn); PQfinish(conn);
exit(ERR_DB_QUERY); exit(ERR_DB_QUERY);
@@ -90,7 +91,8 @@ pg_version(PGconn *conn, char* major_version)
if (PQresultStatus(res) != PGRES_TUPLES_OK) if (PQresultStatus(res) != PGRES_TUPLES_OK)
{ {
fprintf(stderr, "PQexec failed: %s", PQerrorMessage(conn)); log_err(_("Version check PQexec failed: %s"),
PQerrorMessage(conn));
PQclear(res); PQclear(res);
PQfinish(conn); PQfinish(conn);
exit(ERR_DB_QUERY); exit(ERR_DB_QUERY);
@@ -128,7 +130,8 @@ guc_setted(PGconn *conn, const char *parameter, const char *op,
res = PQexec(conn, sqlquery); res = PQexec(conn, sqlquery);
if (PQresultStatus(res) != PGRES_TUPLES_OK) 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); PQclear(res);
PQfinish(conn); PQfinish(conn);
exit(ERR_DB_QUERY); exit(ERR_DB_QUERY);
@@ -159,7 +162,8 @@ get_cluster_size(PGconn *conn)
res = PQexec(conn, sqlquery); res = PQexec(conn, sqlquery);
if (PQresultStatus(res) != PGRES_TUPLES_OK) 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); PQclear(res);
PQfinish(conn); PQfinish(conn);
exit(ERR_DB_QUERY); exit(ERR_DB_QUERY);
@@ -221,7 +225,7 @@ getMasterConnection(PGconn *standby_conn, int id, char *cluster,
res1 = PQexec(standby_conn, sqlquery); res1 = PQexec(standby_conn, sqlquery);
if (PQresultStatus(res1) != PGRES_TUPLES_OK) 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)); PQerrorMessage(standby_conn));
PQclear(res1); PQclear(res1);
PQfinish(standby_conn); PQfinish(standby_conn);
@@ -247,7 +251,7 @@ getMasterConnection(PGconn *standby_conn, int id, char *cluster,
if (PQresultStatus(res2) != PGRES_TUPLES_OK) 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)); PQerrorMessage(master_conn));
PQclear(res2); PQclear(res2);
PQfinish(master_conn); PQfinish(master_conn);

2
log.h
View File

@@ -20,6 +20,8 @@
#ifndef _REPMGR_LOG_H_ #ifndef _REPMGR_LOG_H_
#define _REPMGR_LOG_H_ #define _REPMGR_LOG_H_
#include "repmgr.h"
#define REPMGR_SYSLOG 1 #define REPMGR_SYSLOG 1
#define REPMGR_STDERR 2 #define REPMGR_STDERR 2

View File

@@ -676,7 +676,6 @@ do_standby_clone(void)
case 0: case 0:
/* dest_dir not there, must create it */ /* dest_dir not there, must create it */
log_info(_("creating directory %s ...\n"), runtime_options.dest_dir); log_info(_("creating directory %s ...\n"), runtime_options.dest_dir);
fflush(stdout);
if (!create_directory(runtime_options.dest_dir)) if (!create_directory(runtime_options.dest_dir))
{ {
@@ -687,9 +686,8 @@ do_standby_clone(void)
break; break;
case 1: case 1:
/* Present but empty, fix permissions and use it */ /* 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); runtime_options.dest_dir);
fflush(stdout);
if (!set_directory_permissions(runtime_options.dest_dir)) if (!set_directory_permissions(runtime_options.dest_dir))
{ {
@@ -808,9 +806,7 @@ do_standby_clone(void)
{ {
case 0: case 0:
/* tblspc_dir not there, must create it */ /* tblspc_dir not there, must create it */
if (runtime_options.verbose) log_info(_("creating directory \"%s\"... "), tblspc_dir);
printf(_("creating directory \"%s\"... "), tblspc_dir);
fflush(stdout);
if (!create_directory(tblspc_dir)) if (!create_directory(tblspc_dir))
{ {
@@ -823,10 +819,8 @@ do_standby_clone(void)
break; break;
case 1: case 1:
/* Present but empty, fix permissions and use it */ /* Present but empty, fix permissions and use it */
if (runtime_options.verbose) log_info(_("fixing permissions on existing directory \"%s\"... "),
printf(_("fixing permissions on existing directory \"%s\"... "), tblspc_dir);
tblspc_dir);
fflush(stdout);
if (!set_directory_permissions(tblspc_dir)) if (!set_directory_permissions(tblspc_dir))
{ {
@@ -841,10 +835,8 @@ do_standby_clone(void)
/* Present and not empty */ /* Present and not empty */
if (!runtime_options.force) if (!runtime_options.force)
{ {
fprintf( log_err(_("%s: directory \"%s\" exists but is not empty\n"),
stderr, progname, tblspc_dir);
_("%s: directory \"%s\" exists but is not empty\n"),
progname, tblspc_dir);
PQclear(res); PQclear(res);
PQfinish(conn); PQfinish(conn);
exit(ERR_BAD_CONFIG); exit(ERR_BAD_CONFIG);

View File

@@ -22,6 +22,7 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include "log.h"
#include "strutil.h" #include "strutil.h"
static int xvsnprintf(char *str, size_t size, const char *format, va_list ap); 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) 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); exit(ERR_STR_OVERFLOW);
} }