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
15 changes: 8 additions & 7 deletions cpp/src/arrow/util/logging.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#endif
#include <cstdlib>
#include <iostream>
#include <sstream>

#ifdef ARROW_USE_GLOG

Expand Down Expand Up @@ -63,33 +64,33 @@ 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());
Copy link
Copy Markdown
Member Author

@Avogar Avogar Jan 20, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's more or less ok to throw exception here, because this class is used as temporary object in one line logging. Like:
Log(...) << ...
So most likely we won't get abort because of throwing exception in dextructor while stack unwinding.

}
}

std::ostream& Stream() {
has_logged_ = true;
return std::cerr;
return stream;
}

template <class T>
CerrLog& operator<<(const T& t) {
if (severity_ != ArrowLogLevel::ARROW_DEBUG) {
has_logged_ = true;
std::cerr << t;
stream << t;
}
return *this;
}

protected:
const ArrowLogLevel severity_;
bool has_logged_;
std::stringstream stream;

void PrintBackTrace() {
#ifdef ARROW_WITH_BACKTRACE
Expand Down Expand Up @@ -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<LoggingProvider*>(logging_provider_);
logging_provider_ = nullptr;
Expand Down
4 changes: 2 additions & 2 deletions cpp/src/arrow/util/logging.h
Original file line number Diff line number Diff line change
Expand Up @@ -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; }

Expand All @@ -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.
///
Expand Down