Skip to content

Commit

Permalink
Restore "Check failure stack trace" message on LOG(FATAL)
Browse files Browse the repository at this point in the history
#1074 refactored some of the code to
enable the failure function to throw.  This made it so when
the LogMessageFatal class was used, the error ended up being printed
differently.

Before:
  LOG_AT_LEVEL(google::LogSeverity::FATAL) << "Crash: Hello world!"; ->

  F20240621 18:12:44.710584 139620827212672 log_demo.cc:16] Crash: Hello world!
  *** Check failure stack trace: ***
      @     0x559e2704711a
      @     0x7efc01fac24a
      @     0x7efc01fac305
      @     0x559e27046dd5
  Aborted

  LOG(FATAL) << "Crash: Hello world!"; ->

  F20240621 18:13:05.760556 140518290856832 log_demo.cc:16] Crash: Hello world!
      @     0x55cdc2475130
      @     0x7fccf6fb324a
      @     0x7fccf6fb3305
      @     0x55cdc2474df5
  Aborted

With this patch, they both produce the same output.

Signed-off-by: Austin Schuh <[email protected]>
  • Loading branch information
AustinSchuh committed Jun 22, 2024
1 parent 45f99f5 commit 039298a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/logging.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2541,8 +2541,11 @@ LogMessageFatal::LogMessageFatal(const char* file, int line,
: LogMessage(file, line, result) {}

LogMessageFatal::~LogMessageFatal() noexcept(false) {
Flush();
LogMessage::Fail();
// We really want [[noreturn]] on the destructor so the compiler can use it.
// We really just want to reuse the parent class's destructor since it has all
// the right logic in it.
LogMessage::~LogMessage();
Fail();
}

namespace logging {
Expand Down
6 changes: 6 additions & 0 deletions src/logging_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1586,3 +1586,9 @@ TEST(Logging, FatalThrow) {
ScopedExit<decltype(restore_fail)> restore{restore_fail};
EXPECT_THROW({ LOG(FATAL) << "must throw to fail"; }, std::logic_error);
}

TEST(DeathLogging, ErrorMessage) {
ASSERT_DEATH({ LOG(FATAL) << "foo"; }, "Check failure stack trace");
ASSERT_DEATH({ LOG_AT_LEVEL(google::LogSeverity::FATAL) << "foo"; },
"Check failure stack trace");
}

0 comments on commit 039298a

Please sign in to comment.