Mercurial > hg > orthanc-databases
changeset 429:dbf811b1bb43 pg-transactions
new configuration 'EnableVerboseLogs' to log SQL statements being executed
author | Alain Mazy <am@osimis.io> |
---|---|
date | Thu, 30 Nov 2023 14:47:23 +0100 |
parents | 4d0bacbd0fba |
children | f1f3c5554283 |
files | Framework/PostgreSQL/PostgreSQLDatabase.cpp Framework/PostgreSQL/PostgreSQLDatabase.h Framework/PostgreSQL/PostgreSQLParameters.cpp Framework/PostgreSQL/PostgreSQLParameters.h Framework/PostgreSQL/PostgreSQLResult.cpp Framework/PostgreSQL/PostgreSQLStatement.cpp PostgreSQL/NEWS |
diffstat | 7 files changed, 44 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- a/Framework/PostgreSQL/PostgreSQLDatabase.cpp Thu Nov 30 14:46:38 2023 +0100 +++ b/Framework/PostgreSQL/PostgreSQLDatabase.cpp Thu Nov 30 14:47:23 2023 +0100 @@ -159,7 +159,10 @@ void PostgreSQLDatabase::ExecuteMultiLines(const std::string& sql) { - LOG(TRACE) << "PostgreSQL: " << sql; + if (IsVerboseEnabled()) + { + LOG(INFO) << "PostgreSQL: " << sql; + } Open(); PGresult* result = PQexec(reinterpret_cast<PGconn*>(pg_), sql.c_str());
--- a/Framework/PostgreSQL/PostgreSQLDatabase.h Thu Nov 30 14:46:38 2023 +0100 +++ b/Framework/PostgreSQL/PostgreSQLDatabase.h Thu Nov 30 14:47:23 2023 +0100 @@ -60,6 +60,11 @@ void Open(); + bool IsVerboseEnabled() const + { + return parameters_.IsVerboseEnabled(); + } + bool AcquireAdvisoryLock(int32_t lock); bool ReleaseAdvisoryLock(int32_t lock);
--- a/Framework/PostgreSQL/PostgreSQLParameters.cpp Thu Nov 30 14:46:38 2023 +0100 +++ b/Framework/PostgreSQL/PostgreSQLParameters.cpp Thu Nov 30 14:47:23 2023 +0100 @@ -44,6 +44,7 @@ connectionRetryInterval_ = 5; readWriteTransactionStatement_ = "SET TRANSACTION ISOLATION LEVEL SERIALIZABLE READ WRITE"; readOnlyTransactionStatement_ = "SET TRANSACTION ISOLATION LEVEL SERIALIZABLE READ ONLY"; + isVerboseEnabled_ = false; } @@ -96,6 +97,8 @@ lock_ = configuration.GetBooleanValue("Lock", true); // Use locking by default + isVerboseEnabled_ = configuration.GetBooleanValue("EnableVerboseLogs", false); + maxConnectionRetries_ = configuration.GetUnsignedIntegerValue("MaximumConnectionRetries", 10); connectionRetryInterval_ = configuration.GetUnsignedIntegerValue("ConnectionRetryInterval", 5);
--- a/Framework/PostgreSQL/PostgreSQLParameters.h Thu Nov 30 14:46:38 2023 +0100 +++ b/Framework/PostgreSQL/PostgreSQLParameters.h Thu Nov 30 14:47:23 2023 +0100 @@ -45,6 +45,7 @@ unsigned int connectionRetryInterval_; std::string readWriteTransactionStatement_; std::string readOnlyTransactionStatement_; + bool isVerboseEnabled_; void Reset(); @@ -147,6 +148,17 @@ return readOnlyTransactionStatement_; } + void SetVerboseEnabled(bool enabled) + { + isVerboseEnabled_ = enabled; + } + + bool IsVerboseEnabled() const + { + return isVerboseEnabled_; + } + + void Format(std::string& target) const; }; }
--- a/Framework/PostgreSQL/PostgreSQLResult.cpp Thu Nov 30 14:46:38 2023 +0100 +++ b/Framework/PostgreSQL/PostgreSQLResult.cpp Thu Nov 30 14:47:23 2023 +0100 @@ -84,6 +84,11 @@ position_(0), database_(statement.GetDatabase()) { + if (database_.IsVerboseEnabled()) + { + LOG(INFO) << "PostgreSQL: " << statement.sql_; + } + result_ = statement.Execute(); assert(result_ != NULL); // An exception would have been thrown otherwise
--- a/Framework/PostgreSQL/PostgreSQLStatement.cpp Thu Nov 30 14:46:38 2023 +0100 +++ b/Framework/PostgreSQL/PostgreSQLStatement.cpp Thu Nov 30 14:47:23 2023 +0100 @@ -308,7 +308,10 @@ inputs_(new Inputs), formatter_(Dialect_PostgreSQL) { - LOG(TRACE) << "PostgreSQL: " << sql; + if (database.IsVerboseEnabled()) + { + LOG(TRACE) << "PostgreSQL: " << sql; + } } @@ -319,7 +322,11 @@ formatter_(Dialect_PostgreSQL) { query.Format(sql_, formatter_); - LOG(TRACE) << "PostgreSQL: " << sql_; + + if (database.IsVerboseEnabled()) + { + LOG(TRACE) << "PostgreSQL: " << sql_; + } for (size_t i = 0; i < formatter_.GetParametersCount(); i++) {
--- a/PostgreSQL/NEWS Thu Nov 30 14:46:38 2023 +0100 +++ b/PostgreSQL/NEWS Thu Nov 30 14:47:23 2023 +0100 @@ -1,3 +1,9 @@ +Pending changes in the mainline +=============================== + +* New "EnableVerboseLogs" configuration to show SQL statements being executed. + + Release 5.1 (2023-06-27) ========================