diff --git a/cpp/src/arrow/util/logging.cc b/cpp/src/arrow/util/logging.cc index 04fcf3d3ed618..a72ff802558a2 100644 --- a/cpp/src/arrow/util/logging.cc +++ b/cpp/src/arrow/util/logging.cc @@ -22,6 +22,7 @@ #endif #include #include +#include #ifdef ARROW_USE_GLOG @@ -63,26 +64,25 @@ class CerrLog { public: explicit CerrLog(ArrowLogLevel severity) : severity_(severity), has_logged_(false) {} - virtual ~CerrLog() { + virtual ~CerrLog() noexcept(false) { if (has_logged_) { - std::cerr << std::endl; + stream << std::endl; } if (severity_ == ArrowLogLevel::ARROW_FATAL) { - PrintBackTrace(); - std::abort(); + throw std::runtime_error(stream.str()); } } std::ostream& Stream() { has_logged_ = true; - return std::cerr; + return stream; } template CerrLog& operator<<(const T& t) { if (severity_ != ArrowLogLevel::ARROW_DEBUG) { has_logged_ = true; - std::cerr << t; + stream << t; } return *this; } @@ -90,6 +90,7 @@ class CerrLog { protected: const ArrowLogLevel severity_; bool has_logged_; + std::stringstream stream; void PrintBackTrace() { #ifdef ARROW_WITH_BACKTRACE @@ -245,7 +246,7 @@ std::ostream& ArrowLog::Stream() { bool ArrowLog::IsEnabled() const { return is_enabled_; } -ArrowLog::~ArrowLog() { +ArrowLog::~ArrowLog() noexcept(false) { if (logging_provider_ != nullptr) { delete reinterpret_cast(logging_provider_); logging_provider_ = nullptr; diff --git a/cpp/src/arrow/util/logging.h b/cpp/src/arrow/util/logging.h index 15a0188ab7613..d529daee2173b 100644 --- a/cpp/src/arrow/util/logging.h +++ b/cpp/src/arrow/util/logging.h @@ -157,7 +157,7 @@ enum class ArrowLogLevel : int { // This is also a null log which does not output anything. class ARROW_EXPORT ArrowLogBase { public: - virtual ~ArrowLogBase() {} + virtual ~ArrowLogBase() noexcept(false) {} virtual bool IsEnabled() const { return false; } @@ -176,7 +176,7 @@ class ARROW_EXPORT ArrowLogBase { class ARROW_EXPORT ArrowLog : public ArrowLogBase { public: ArrowLog(const char* file_name, int line_number, ArrowLogLevel severity); - ~ArrowLog() override; + ~ArrowLog() noexcept(false) override; /// Return whether or not current logging instance is enabled. ///