From a4214d95c98c160667d1fe90203d1ce9fda53ae9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kjell=20Hedstr=C3=B6m?= <331742+KjellKod@users.noreply.github.com> Date: Tue, 5 Dec 2023 20:12:48 -0700 Subject: [PATCH] fixed formatting --- src/g3log.cpp | 76 +++++++++++++++++++++++---------------------- src/g3log/g3log.hpp | 2 +- 2 files changed, 40 insertions(+), 38 deletions(-) diff --git a/src/g3log.cpp b/src/g3log.cpp index 6fe5df81..9b4386d4 100644 --- a/src/g3log.cpp +++ b/src/g3log.cpp @@ -147,42 +147,40 @@ namespace g3 { message.get()->write().append(entry); message.get()->setExpression(boolean_expression); - if (internal::wasFatal(level)) - { + 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! - setFatalPreLoggingHook(g_pre_fatal_hook_that_does_nothing); - ++g_fatal_hook_recursive_counter; // thread safe counter - // "benign" race here. If two threads crashes, with recursive crashes - // then it's possible that the "other" fatal stack trace will be shown - // that's OK since it was anyhow the first crash detected - static const std::string first_stack_trace = stack_trace; - fatalhook(); - message.get()->write().append(stack_trace); - - if (g_fatal_hook_recursive_counter.load() > 1) - { - message.get()->write().append("\n\n\nWARNING\n" - "A recursive crash detected. It is likely the hook set with 'setFatalPreLoggingHook(...)' is responsible\n\n") - .append("---First crash stacktrace: ") - .append(first_stack_trace) - .append("\n---End of first stacktrace\n"); - } - FatalMessagePtr fatal_message{std::make_unique(*(message._move_only.get()), fatal_signal)}; - // At destruction, flushes fatal message to g3LogWorker - // either we will stay here until the background worker has received the fatal - // 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); + 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! + setFatalPreLoggingHook(g_pre_fatal_hook_that_does_nothing); + ++g_fatal_hook_recursive_counter; // thread safe counter + // "benign" race here. If two threads crashes, with recursive crashes + // then it's possible that the "other" fatal stack trace will be shown + // that's OK since it was anyhow the first crash detected + static const std::string first_stack_trace = stack_trace; + fatalhook(); + message.get()->write().append(stack_trace); + + if (g_fatal_hook_recursive_counter.load() > 1) { + message.get()->write().append( + "\n\n\nWARNING\n" + "A recursive crash detected. It is likely the hook set with 'setFatalPreLoggingHook(...)' is responsible\n\n") + .append("---First crash stacktrace: ") + .append(first_stack_trace) + .append("\n---End of first stacktrace\n"); + } + FatalMessagePtr fatal_message{std::make_unique(*(message._move_only.get()), fatal_signal)}; + // At destruction, flushes fatal message to g3LogWorker + // either we will stay here until the background worker has received the fatal + // 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); } /** * save the message to the logger. In case of called before the logger is instantiated @@ -236,16 +234,20 @@ namespace g3 { std::this_thread::sleep_for(std::chrono::seconds(1)); } } + g_logger_instance->fatal(message); + while (shouldBlockForFatalHandling()) { + std::this_thread::sleep_for(std::chrono::seconds(1)); + } + } - /** The default, initial, handling to send a 'fatal' event to g3logworker + /** The default, initial, handling to send a 'fatal' event to g3logworker * the caller will stay here, eternally, until the software is aborted * ... in the case of unit testing it is the given "Mock" fatalCall that will * define the behaviour. */ - void fatalCall(FatalMessagePtr message) - { - g_fatal_to_g3logworker_function_ptr(FatalMessagePtr{std::move(message)}); - } + void fatalCall(FatalMessagePtr message) { + g_fatal_to_g3logworker_function_ptr(FatalMessagePtr{std::move(message)}); + } - } // internal -} // g3 + } // namespace internal +} // namespace g3 diff --git a/src/g3log/g3log.hpp b/src/g3log/g3log.hpp index f8ae3151..37c54506 100644 --- a/src/g3log/g3log.hpp +++ b/src/g3log/g3log.hpp @@ -106,7 +106,7 @@ 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); + 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);