Skip to content

Commit

Permalink
Convert more uses of fprintf to use logger
Browse files Browse the repository at this point in the history
  • Loading branch information
Greg Smith authored and Greg Smith committed Feb 23, 2011
1 parent 3b2203c commit 18ef5b3
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 25 deletions.
4 changes: 2 additions & 2 deletions check_dir.c
Expand Up @@ -29,7 +29,7 @@
#include "check_dir.h"

#include "strutil.h"

#include "log.h"

static int mkdir_p(char *path, mode_t omode);

Expand Down Expand Up @@ -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;
Expand Down
20 changes: 12 additions & 8 deletions dbutils.c
Expand Up @@ -18,8 +18,8 @@
*/

#include "repmgr.h"

#include "strutil.h"
#include "log.h"

PGconn *
establishDBConnection(const char *conninfo, const bool exit_on_error)
Expand All @@ -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)
Expand All @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand Down
2 changes: 2 additions & 0 deletions log.h
Expand Up @@ -20,6 +20,8 @@
#ifndef _REPMGR_LOG_H_
#define _REPMGR_LOG_H_

#include "repmgr.h"

#define REPMGR_SYSLOG 1
#define REPMGR_STDERR 2

Expand Down
20 changes: 6 additions & 14 deletions repmgr.c
Expand Up @@ -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))
{
Expand All @@ -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))
{
Expand Down Expand Up @@ -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))
{
Expand All @@ -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))
{
Expand All @@ -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);
Expand Down
4 changes: 3 additions & 1 deletion strutil.c
Expand Up @@ -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);
Expand All @@ -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);
}

Expand Down

0 comments on commit 18ef5b3

Please sign in to comment.