refactor fatal call (#511)

* refactor fatal handling
This commit is contained in:
Kjell Hedström - seeking Senior Engineering roles as well as contract opportunities 2023-12-05 21:04:01 -07:00 committed by GitHub
parent d70ae50ee3
commit bba825815a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 48 additions and 44 deletions

BIN
.DS_Store vendored Normal file

Binary file not shown.

BIN
docs/.DS_Store vendored Normal file

Binary file not shown.

View File

@ -148,6 +148,13 @@ namespace g3 {
message.get()->setExpression(boolean_expression);
if (internal::wasFatal(level)) {
saveFatalMessage(level, stack_trace, message, fatal_signal);
} else {
pushMessageToLogger(message);
}
}
void saveFatalMessage(const LEVELS& level, const char* stack_trace, g3::LogMessagePtr& message, int& fatal_signal) {
auto fatalhook = g_fatal_pre_logging_hook;
// In case the fatal_pre logging actually will cause a crash in its turn
// let's not do recursive crashing!
@ -174,11 +181,7 @@ namespace g3 {
// message, flushed the crash message to the sinks and exits with the same fatal signal
//..... OR it's in unit-test mode then we throw a std::runtime_error (and never hit sleep)
fatalCall(fatal_message);
} else {
pushMessageToLogger(message);
}
}
/**
* save the message to the logger. In case of called before the logger is instantiated
* the first message will be saved. Any following subsequent uninitialized log calls
@ -197,8 +200,7 @@ namespace g3 {
std::string& str = g_first_uninitialized_msg->write();
str.clear();
str.append(err); // replace content
std::cerr << str << std::endl;
});
std::cerr << str << std::endl; });
return;
}

View File

@ -106,6 +106,8 @@ namespace g3 {
void saveMessage(const char* message, const char* file, int line, const char* function, const LEVELS& level,
const char* boolean_expression, int fatal_signal, const char* stack_trace);
void saveFatalMessage(const LEVELS& level, const char* stack_trace, g3::LogMessagePtr& message, int& fatal_signal);
// forwards the message to all sinks
void pushMessageToLogger(LogMessagePtr log_entry);