Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions include/cassandra.h
Original file line number Diff line number Diff line change
Expand Up @@ -11298,6 +11298,15 @@ CASS_EXPORT void
cass_log_set_callback(CassLogCallback callback,
void* data);

/**
* Analogous getter - useful for restoring logger to previous values.
*
* @param[out] callback_out Current logging callback. Must point to a valid memory area.
* @param[out] data_out Current Logger instance. Must point to a valid memory area.
*/
CASS_EXPORT void
cass_log_get_callback_and_data(CassLogCallback* callback_out, void** data_out);

/**
* Sets the log queue size.
*
Expand Down
9 changes: 9 additions & 0 deletions src/logger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ void cass_log_set_callback(CassLogCallback callback, void* data) {
Logger::set_callback(callback, data);
}

void cass_log_get_callback_and_data(CassLogCallback* callback_out, void** data_out) {
Logger::get_callback_and_data(callback_out, data_out);
}

void cass_log_set_queue_size(size_t queue_size) {
// Deprecated
}
Expand Down Expand Up @@ -66,3 +70,8 @@ void Logger::set_callback(CassLogCallback cb, void* data) {
cb_ = cb == NULL ? noop_log_callback : cb;
data_ = data;
}

void Logger::get_callback_and_data(CassLogCallback* cb_out, void** data_out) {
*cb_out = cb_;
*data_out = data_;
}
1 change: 1 addition & 0 deletions src/logger.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class Logger {
public:
static void set_log_level(CassLogLevel level);
static void set_callback(CassLogCallback cb, void* data);
static void get_callback_and_data(CassLogCallback* cb_out, void** data_out);

#if defined(__GNUC__) || defined(__clang__)
#define ATTR_FORMAT(string, first) __attribute__((__format__(__printf__, string, first)))
Expand Down
8 changes: 8 additions & 0 deletions tests/src/integration/logger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ Logger::~Logger() {
if (output_.is_open()) {
output_.close();
}
if (restore_old_logger_) {
// `initialize` has beed called, so let's restore global logger
cass_log_set_callback(old_log_callback_, old_data_);
}
}

void Logger::initialize(const std::string& test_case, const std::string& test_name) {
Expand Down Expand Up @@ -72,6 +76,10 @@ void Logger::initialize(const std::string& test_case, const std::string& test_na

// Set the maximum driver log level to capture all logs messages
cass_log_set_level(CASS_LOG_TRACE);

// Remember the old logger before setting it (to be restored in dtor)
cass_log_get_callback_and_data(&old_log_callback_, &old_data_);
restore_old_logger_ = true;
cass_log_set_callback(Logger::log, this);
}

Expand Down
5 changes: 5 additions & 0 deletions tests/src/integration/logger.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,11 @@ class Logger {
* Number of log messages that match the search criteria
*/
size_t count_;

/** We need these to restore the globals on teardown. */
bool restore_old_logger_ = false;
CassLogCallback old_log_callback_;
void* old_data_;

/**
* Log the message from the driver (callback)
Expand Down