Skip to content
This repository was archived by the owner on Jun 30, 2025. It is now read-only.

Commit 039298a

Browse files
committed
Restore "Check failure stack trace" message on LOG(FATAL)
#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]>
1 parent 45f99f5 commit 039298a

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

src/logging.cc

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2541,8 +2541,11 @@ LogMessageFatal::LogMessageFatal(const char* file, int line,
25412541
: LogMessage(file, line, result) {}
25422542

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

25482551
namespace logging {

src/logging_unittest.cc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1586,3 +1586,9 @@ TEST(Logging, FatalThrow) {
15861586
ScopedExit<decltype(restore_fail)> restore{restore_fail};
15871587
EXPECT_THROW({ LOG(FATAL) << "must throw to fail"; }, std::logic_error);
15881588
}
1589+
1590+
TEST(DeathLogging, ErrorMessage) {
1591+
ASSERT_DEATH({ LOG(FATAL) << "foo"; }, "Check failure stack trace");
1592+
ASSERT_DEATH({ LOG_AT_LEVEL(google::LogSeverity::FATAL) << "foo"; },
1593+
"Check failure stack trace");
1594+
}

0 commit comments

Comments
 (0)