Skip to content

Commit fee0795

Browse files
committed
Enable Driver Logging
Add todo to update logging system later Add logs
1 parent 598068f commit fee0795

7 files changed

Lines changed: 82 additions & 19 deletions

File tree

cpp/src/arrow/flight/sql/odbc/flight_sql/address_info.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@
1919

2020
#include <string>
2121

22-
#include <arrow/flight/sql/odbc/odbcabstraction/include/odbcabstraction/platform.h>
22+
#include "arrow/flight/sql/odbc/odbcabstraction/include/odbcabstraction/platform.h"
23+
2324
#include <sys/types.h>
2425
#include <cstdint>
2526
#if !_WIN32

cpp/src/arrow/flight/sql/odbc/flight_sql/flight_sql_driver.cc

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,11 @@
2020
#include "arrow/flight/sql/odbc/odbcabstraction/include/odbcabstraction/platform.h"
2121
#include "arrow/flight/sql/odbc/odbcabstraction/include/odbcabstraction/spd_logger.h"
2222
#include "arrow/flight/sql/odbc/odbcabstraction/include/odbcabstraction/utils.h"
23+
#include "arrow/util/io_util.h"
2324

2425
#define DEFAULT_MAXIMUM_FILE_SIZE 16777216
2526
#define CONFIG_FILE_NAME "arrow-odbc.ini"
27+
#define CONFIG_FILE_PATH "CONFIG_FILE_PATH"
2628

2729
namespace driver {
2830
namespace flight_sql {
@@ -52,7 +54,9 @@ LogLevel ToLogLevel(int64_t level) {
5254
} // namespace
5355

5456
FlightSqlDriver::FlightSqlDriver()
55-
: diagnostics_("Apache Arrow", "Flight SQL", OdbcVersion::V_3), version_("0.9.0.0") {}
57+
: diagnostics_("Apache Arrow", "Flight SQL", OdbcVersion::V_3), version_("0.9.0.0") {
58+
RegisterLog();
59+
}
5660

5761
std::shared_ptr<Connection> FlightSqlDriver::CreateConnection(OdbcVersion odbc_version) {
5862
return std::make_shared<FlightSqlConnection>(odbc_version, version_);
@@ -63,14 +67,19 @@ odbcabstraction::Diagnostics& FlightSqlDriver::GetDiagnostics() { return diagnos
6367
void FlightSqlDriver::SetVersion(std::string version) { version_ = std::move(version); }
6468

6569
void FlightSqlDriver::RegisterLog() {
70+
std::string config_path = arrow::internal::GetEnvVar(CONFIG_FILE_PATH).ValueOr("");
71+
if (config_path.empty()) {
72+
return;
73+
}
74+
6675
odbcabstraction::PropertyMap propertyMap;
67-
driver::odbcabstraction::ReadConfigFile(propertyMap, CONFIG_FILE_NAME);
76+
driver::odbcabstraction::ReadConfigFile(propertyMap, config_path, CONFIG_FILE_NAME);
6877

6978
auto log_enable_iterator = propertyMap.find(std::string(SPDLogger::LOG_ENABLED));
7079
auto log_enabled = log_enable_iterator != propertyMap.end()
7180
? odbcabstraction::AsBool(log_enable_iterator->second)
7281
: false;
73-
if (!log_enabled) {
82+
if (!log_enabled.get()) {
7483
return;
7584
}
7685

cpp/src/arrow/flight/sql/odbc/flight_sql/win_system_dsn.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#include "arrow/flight/sql/odbc/flight_sql/include/flight_sql/ui/window.h"
3030
#include "arrow/flight/sql/odbc/flight_sql/system_dsn.h"
3131
#include "arrow/flight/sql/odbc/odbcabstraction/include/odbcabstraction/exceptions.h"
32+
#include "arrow/flight/sql/odbc/odbcabstraction/include/odbcabstraction/logger.h"
3233

3334
#include <odbcinst.h>
3435
#include <codecvt>
@@ -87,7 +88,7 @@ bool DisplayConnectionWindow(void* windowParent, Configuration& config,
8788
properties = config.GetProperties();
8889
return true;
8990
} else {
90-
// TODO: log cancelled dialog after logging is enabled.
91+
LOG_INFO("Dialog is cancelled by user");
9192
return false;
9293
}
9394
}

cpp/src/arrow/flight/sql/odbc/odbc_api.cc

Lines changed: 58 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,15 @@
1818
// flight_sql_connection.h needs to be included first due to conflicts with windows.h
1919
#include "arrow/flight/sql/odbc/flight_sql/flight_sql_connection.h"
2020

21-
#include <arrow/flight/sql/odbc/flight_sql/include/flight_sql/flight_sql_driver.h>
22-
#include <arrow/flight/sql/odbc/odbcabstraction/include/odbcabstraction/diagnostics.h>
23-
#include <arrow/flight/sql/odbc/odbcabstraction/include/odbcabstraction/odbc_impl/encoding_utils.h>
24-
#include <arrow/flight/sql/odbc/odbcabstraction/include/odbcabstraction/odbc_impl/odbc_connection.h>
25-
#include <arrow/flight/sql/odbc/odbcabstraction/include/odbcabstraction/odbc_impl/odbc_environment.h>
26-
#include <arrow/flight/sql/odbc/odbcabstraction/include/odbcabstraction/spi/connection.h>
27-
2821
#include "arrow/flight/sql/odbc/flight_sql/include/flight_sql/config/configuration.h"
22+
#include "arrow/flight/sql/odbc/flight_sql/include/flight_sql/flight_sql_driver.h"
23+
#include "arrow/flight/sql/odbc/odbcabstraction/include/odbcabstraction/diagnostics.h"
24+
#include "arrow/flight/sql/odbc/odbcabstraction/include/odbcabstraction/logger.h"
2925
#include "arrow/flight/sql/odbc/odbcabstraction/include/odbcabstraction/odbc_impl/attribute_utils.h"
26+
#include "arrow/flight/sql/odbc/odbcabstraction/include/odbcabstraction/odbc_impl/encoding_utils.h"
27+
#include "arrow/flight/sql/odbc/odbcabstraction/include/odbcabstraction/odbc_impl/odbc_connection.h"
28+
#include "arrow/flight/sql/odbc/odbcabstraction/include/odbcabstraction/odbc_impl/odbc_environment.h"
29+
#include "arrow/flight/sql/odbc/odbcabstraction/include/odbcabstraction/spi/connection.h"
3030

3131
#if defined _WIN32 || defined _WIN64
3232
// For displaying DSN Window
@@ -35,10 +35,13 @@
3535

3636
// odbc_api includes windows.h, which needs to be put behind winsock2.h.
3737
// odbc_environment.h includes winsock2.h
38-
#include <arrow/flight/sql/odbc/odbc_api.h>
38+
#include "arrow/flight/sql/odbc/odbc_api.h"
3939

4040
namespace arrow {
4141
SQLRETURN SQLAllocHandle(SQLSMALLINT type, SQLHANDLE parent, SQLHANDLE* result) {
42+
LOG_DEBUG("SQLAllocHandle called with type: {}, parent: {}, result: {}", type, parent,
43+
fmt::ptr(result));
44+
4245
*result = nullptr;
4346

4447
switch (type) {
@@ -93,6 +96,8 @@ SQLRETURN SQLAllocHandle(SQLSMALLINT type, SQLHANDLE parent, SQLHANDLE* result)
9396
}
9497

9598
SQLRETURN SQLFreeHandle(SQLSMALLINT type, SQLHANDLE handle) {
99+
LOG_DEBUG("SQLFreeHandle called with type: {}, handle: {}", type, handle);
100+
96101
switch (type) {
97102
case SQL_HANDLE_ENV: {
98103
using ODBC::ODBCEnvironment;
@@ -160,6 +165,12 @@ SQLRETURN SQLGetDiagFieldW(SQLSMALLINT handleType, SQLHANDLE handle,
160165
using ODBC::ODBCConnection;
161166
using ODBC::ODBCEnvironment;
162167

168+
LOG_DEBUG(
169+
"SQLGetDiagFieldW called with handleType: {}, handle: {}, recNumber: {}, "
170+
"diagIdentifier: {}, diagInfoPtr: {}, bufferLength: {}, stringLengthPtr: {}",
171+
handleType, handle, recNumber, diagIdentifier, diagInfoPtr, bufferLength,
172+
fmt::ptr(stringLengthPtr));
173+
163174
if (!handle) {
164175
return SQL_INVALID_HANDLE;
165176
}
@@ -369,6 +380,13 @@ SQLRETURN SQLGetDiagRecW(SQLSMALLINT handleType, SQLHANDLE handle, SQLSMALLINT r
369380
using ODBC::ODBCConnection;
370381
using ODBC::ODBCEnvironment;
371382

383+
LOG_DEBUG(
384+
"SQLGetDiagRecW called with handleType: {}, handle: {}, recNumber: {}, "
385+
"sqlState: {}, nativeErrorPtr: {}, messageText: {}, bufferLength: {}, "
386+
"textLengthPtr: {}",
387+
handleType, handle, recNumber, fmt::ptr(sqlState), fmt::ptr(nativeErrorPtr),
388+
fmt::ptr(messageText), bufferLength, fmt::ptr(textLengthPtr));
389+
372390
if (!handle) {
373391
return SQL_INVALID_HANDLE;
374392
}
@@ -438,10 +456,15 @@ SQLRETURN SQLGetDiagRecW(SQLSMALLINT handleType, SQLHANDLE handle, SQLSMALLINT r
438456
}
439457

440458
SQLRETURN SQLGetEnvAttr(SQLHENV env, SQLINTEGER attr, SQLPOINTER valuePtr,
441-
SQLINTEGER bufferLen, SQLINTEGER* strLenPtr) {
459+
SQLINTEGER bufferLength, SQLINTEGER* strLenPtr) {
442460
using driver::odbcabstraction::DriverException;
443461
using ODBC::ODBCEnvironment;
444462

463+
LOG_DEBUG(
464+
"SQLGetEnvAttr called with env: {}, attr: {}, valuePtr: {}, "
465+
"bufferLength: {}, strLenPtr: {}",
466+
env, attr, valuePtr, bufferLength, fmt::ptr(strLenPtr));
467+
445468
ODBCEnvironment* environment = reinterpret_cast<ODBCEnvironment*>(env);
446469

447470
return ODBCEnvironment::ExecuteWithDiagnostics(environment, SQL_ERROR, [=]() {
@@ -498,6 +521,11 @@ SQLRETURN SQLSetEnvAttr(SQLHENV env, SQLINTEGER attr, SQLPOINTER valuePtr,
498521
using driver::odbcabstraction::DriverException;
499522
using ODBC::ODBCEnvironment;
500523

524+
LOG_DEBUG(
525+
"SQLSetEnvAttr called with env: {}, attr: {}, valuePtr: {}, "
526+
"strLen: {}",
527+
env, attr, valuePtr, strLen);
528+
501529
ODBCEnvironment* environment = reinterpret_cast<ODBCEnvironment*>(env);
502530

503531
return ODBCEnvironment::ExecuteWithDiagnostics(environment, SQL_ERROR, [=]() {
@@ -557,6 +585,14 @@ SQLRETURN SQLDriverConnectW(SQLHDBC conn, SQLHWND windowHandle,
557585
using driver::odbcabstraction::DriverException;
558586
using ODBC::ODBCConnection;
559587

588+
LOG_DEBUG(
589+
"SQLDriverConnectW called with conn: {}, windowHandle: {}, inConnectionString: {}, "
590+
"inConnectionStringLen: {}, outConnectionString: {}, outConnectionStringBufferLen: "
591+
"{}, outConnectionStringLen: {}, driverCompletion: {}",
592+
conn, fmt::ptr(windowHandle), fmt::ptr(inConnectionString), inConnectionStringLen,
593+
fmt::ptr(outConnectionString), outConnectionStringBufferLen,
594+
fmt::ptr(outConnectionStringLen), driverCompletion);
595+
560596
return ODBCConnection::ExecuteWithDiagnostics(conn, SQL_ERROR, [=]() {
561597
ODBCConnection* connection = reinterpret_cast<ODBCConnection*>(conn);
562598
std::string connection_string =
@@ -621,6 +657,12 @@ SQLRETURN SQLConnectW(SQLHDBC conn, SQLWCHAR* dsnName, SQLSMALLINT dsnNameLen,
621657

622658
using ODBC::SqlWcharToString;
623659

660+
LOG_DEBUG(
661+
"SQLConnectW called with conn: {}, dsnName: {}, dsnNameLen: {}, userName: {}, "
662+
"userNameLen: {}, password: {}, passwordLen: {}",
663+
conn, fmt::ptr(dsnName), dsnNameLen, fmt::ptr(userName), userNameLen,
664+
fmt::ptr(password), passwordLen);
665+
624666
return ODBCConnection::ExecuteWithDiagnostics(conn, SQL_ERROR, [=]() {
625667
ODBCConnection* connection = reinterpret_cast<ODBCConnection*>(conn);
626668
std::string dsn = SqlWcharToString(dsnName, dsnNameLen);
@@ -649,6 +691,8 @@ SQLRETURN SQLConnectW(SQLHDBC conn, SQLWCHAR* dsnName, SQLSMALLINT dsnNameLen,
649691
SQLRETURN SQLDisconnect(SQLHDBC conn) {
650692
using ODBC::ODBCConnection;
651693

694+
LOG_DEBUG("SQLDisconnect called with conn: {}", conn);
695+
652696
return ODBCConnection::ExecuteWithDiagnostics(conn, SQL_ERROR, [=]() {
653697
ODBCConnection* connection = reinterpret_cast<ODBCConnection*>(conn);
654698

@@ -663,6 +707,11 @@ SQLRETURN SQLGetInfoW(SQLHDBC conn, SQLUSMALLINT infoType, SQLPOINTER infoValueP
663707
// TODO: complete implementation of SQLGetInfoW and write tests
664708
using ODBC::ODBCConnection;
665709

710+
LOG_DEBUG(
711+
"SQLGetInfoW called with conn: {}, infoType: {}, infoValuePtr: {}, bufLen: {}, "
712+
"length: {}",
713+
conn, infoType, infoValuePtr, bufLen, fmt::ptr(length));
714+
666715
return ODBCConnection::ExecuteWithDiagnostics(conn, SQL_ERROR, [=]() {
667716
ODBCConnection* connection = reinterpret_cast<ODBCConnection*>(conn);
668717

cpp/src/arrow/flight/sql/odbc/odbcabstraction/include/odbcabstraction/logger.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,10 @@
2020
#include <functional>
2121
#include <string>
2222

23-
#include <spdlog/fmt/bundled/format.h>
23+
#include <spdlog/fmt/fmt.h>
24+
25+
// The logger using spdlog is deprecated and will be replaced.
26+
// TODO: mirgate logging to use Arrow's internal logging system
2427

2528
#define __LAZY_LOG(LEVEL, ...) \
2629
do { \

cpp/src/arrow/flight/sql/odbc/odbcabstraction/include/odbcabstraction/utils.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,8 @@ boost::optional<int32_t> AsInt32(int32_t min_value,
5252
const Connection::ConnPropertyMap& connPropertyMap,
5353
const std::string_view& property_name);
5454

55-
void ReadConfigFile(PropertyMap& properties, const std::string& configFileName);
55+
void ReadConfigFile(PropertyMap& properties, const std::string& configPath,
56+
const std::string& configFileName);
5657

5758
} // namespace odbcabstraction
5859
} // namespace driver

cpp/src/arrow/flight/sql/odbc/odbcabstraction/utils.cc

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,8 @@ std::string GetModulePath() {
8181
return std::string(path.begin(), path.begin() + dirname_length);
8282
}
8383

84-
void ReadConfigFile(PropertyMap& properties, const std::string& config_file_name) {
85-
auto config_path = GetModulePath();
86-
84+
void ReadConfigFile(PropertyMap& properties, const std::string& config_path,
85+
const std::string& config_file_name) {
8786
std::ifstream config_file;
8887
auto config_file_path = config_path + "/" + config_file_name;
8988
config_file.open(config_file_path);

0 commit comments

Comments
 (0)