From b1750843008b7928c72699c592776fb56c66ec26 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?louiz=E2=80=99?= Date: Fri, 16 Feb 2018 00:57:49 +0100 Subject: Log the warn/error messages coming from libpq in a correct format --- src/database/postgresql_engine.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'src/database') diff --git a/src/database/postgresql_engine.cpp b/src/database/postgresql_engine.cpp index 518c23a..59bc885 100644 --- a/src/database/postgresql_engine.cpp +++ b/src/database/postgresql_engine.cpp @@ -11,6 +11,8 @@ #include +#include + PostgresqlEngine::PostgresqlEngine(PGconn*const conn): conn(conn) {} @@ -20,6 +22,15 @@ PostgresqlEngine::~PostgresqlEngine() PQfinish(this->conn); } +static void logging_notice_processor(void*, const char* original) +{ + if (original && std::strlen(original) > 0) + { + std::string message{original, std::strlen(original) - 1}; + log_warning("PostgreSQL: ", message); + } +} + std::unique_ptr PostgresqlEngine::open(const std::string& conninfo) { PGconn* con = PQconnectdb(conninfo.data()); @@ -37,6 +48,7 @@ std::unique_ptr PostgresqlEngine::open(const std::string& connin PQfinish(con); throw std::runtime_error("failed to open connection."); } + PQsetNoticeProcessor(con, &logging_notice_processor, nullptr); return std::make_unique(con); } -- cgit v1.2.3