Skip to content

Commit

Permalink
Merge pull request #16 from ClickHouse/remove-abort-in-logging
Browse files Browse the repository at this point in the history
Don't abort in ~CerrLog
  • Loading branch information
Avogar authored Jan 20, 2023
2 parents 450a563 + d7d8237 commit d03245f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
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());
}
}

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

0 comments on commit d03245f

Please sign in to comment.