Restore "Check failure stack trace" message on LOG(FATAL)
https://github.com/google/glog/pull/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 <austin.linux@gmail.com>
This commit is contained in:
parent
45f99f5e1a
commit
039298ac3c
@ -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 {
|
||||
|
||||
@ -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");
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user