aboutsummaryrefslogtreecommitdiff
path: root/src/bin/psql/startup.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/bin/psql/startup.c')
-rw-r--r--src/bin/psql/startup.c50
1 files changed, 38 insertions, 12 deletions
diff --git a/src/bin/psql/startup.c b/src/bin/psql/startup.c
index e1c0754a554..ac82087445e 100644
--- a/src/bin/psql/startup.c
+++ b/src/bin/psql/startup.c
@@ -22,6 +22,7 @@
#include "help.h"
#include "input.h"
#include "mainloop.h"
+#include "fe_utils/logging.h"
#include "fe_utils/print.h"
#include "settings.h"
@@ -89,6 +90,28 @@ static void EstablishVariableSpace(void);
#define NOPAGER 0
+static void
+log_pre_callback(void)
+{
+ if (pset.queryFout && pset.queryFout != stdout)
+ fflush(pset.queryFout);
+}
+
+static void
+log_locus_callback(const char **filename, uint64 *lineno)
+{
+ if (pset.inputfile)
+ {
+ *filename = pset.inputfile;
+ *lineno = pset.lineno;
+ }
+ else
+ {
+ *filename = NULL;
+ *lineno = 0;
+ }
+}
+
/*
*
* main
@@ -103,6 +126,9 @@ main(int argc, char *argv[])
char password[100];
bool new_pass;
+ pg_logging_init(argv[0]);
+ pg_logging_set_pre_callback(log_pre_callback);
+ pg_logging_set_locus_callback(log_locus_callback);
set_pglocale_pgservice(argv[0], PG_TEXTDOMAIN("psql"));
if (argc > 1)
@@ -119,10 +145,6 @@ main(int argc, char *argv[])
}
}
-#ifdef WIN32
- setvbuf(stderr, NULL, _IONBF, 0);
-#endif
-
pset.progname = get_progname(argv[0]);
pset.db = NULL;
@@ -190,7 +212,7 @@ main(int argc, char *argv[])
/* Bail out if -1 was specified but will be ignored. */
if (options.single_txn && options.actions.head == NULL)
{
- fprintf(stderr, _("%s: -1 can only be used in non-interactive mode\n"), pset.progname);
+ pg_log_fatal("-1 can only be used in non-interactive mode");
exit(EXIT_FAILURE);
}
@@ -277,7 +299,7 @@ main(int argc, char *argv[])
if (PQstatus(pset.db) == CONNECTION_BAD)
{
- fprintf(stderr, "%s: %s", pset.progname, PQerrorMessage(pset.db));
+ pg_log_error("could not connect to server: %s", PQerrorMessage(pset.db));
PQfinish(pset.db);
exit(EXIT_BADCONN);
}
@@ -305,8 +327,8 @@ main(int argc, char *argv[])
pset.logfile = fopen(options.logfilename, "a");
if (!pset.logfile)
{
- fprintf(stderr, _("%s: could not open log file \"%s\": %s\n"),
- pset.progname, options.logfilename, strerror(errno));
+ pg_log_fatal("could not open log file \"%s\": %m",
+ options.logfilename);
exit(EXIT_FAILURE);
}
}
@@ -343,6 +365,8 @@ main(int argc, char *argv[])
{
if (cell->action == ACT_SINGLE_QUERY)
{
+ pg_logging_config(PG_LOG_FLAG_TERSE);
+
if (pset.echo == PSQL_ECHO_ALL)
puts(cell->val);
@@ -354,6 +378,8 @@ main(int argc, char *argv[])
PsqlScanState scan_state;
ConditionalStack cond_stack;
+ pg_logging_config(PG_LOG_FLAG_TERSE);
+
if (pset.echo == PSQL_ECHO_ALL)
puts(cell->val);
@@ -562,7 +588,7 @@ parse_psql_options(int argc, char *argv[], struct adhoc_opts *options)
if (!result)
{
- fprintf(stderr, _("%s: could not set printing parameter \"%s\"\n"), pset.progname, value);
+ pg_log_fatal("could not set printing parameter \"%s\"", value);
exit(EXIT_FAILURE);
}
@@ -684,8 +710,8 @@ parse_psql_options(int argc, char *argv[], struct adhoc_opts *options)
else if (!options->username)
options->username = argv[optind];
else if (!pset.quiet)
- fprintf(stderr, _("%s: warning: extra command-line argument \"%s\" ignored\n"),
- pset.progname, argv[optind]);
+ pg_log_warning("extra command-line argument \"%s\" ignored",
+ argv[optind]);
optind++;
}
@@ -733,7 +759,7 @@ process_psqlrc(char *argv0)
if (find_my_exec(argv0, my_exec_path) < 0)
{
- fprintf(stderr, _("%s: could not find own program executable\n"), argv0);
+ pg_log_fatal("could not find own program executable");
exit(EXIT_FAILURE);
}