diff --git a/src/util/Assert.cpp b/src/util/Assert.cpp index 87165d607b..94f415951d 100644 --- a/src/util/Assert.cpp +++ b/src/util/Assert.cpp @@ -54,10 +54,10 @@ OnAssert::resetAction() void OnAssert::defaultAction(std::string_view message) { - if (LogServiceState::initialized()) { + if (LogServiceState::initialized() and LogServiceState::hasSinks()) { LOG(LogService::fatal()) << message; } else { - std::cerr << message; + std::cerr << message << std::endl; } std::exit(EXIT_FAILURE); // std::abort does not flush gcovr output and causes uncovered lines } diff --git a/src/util/log/Logger.cpp b/src/util/log/Logger.cpp index 5a3c2f771c..28b6cab143 100644 --- a/src/util/log/Logger.cpp +++ b/src/util/log/Logger.cpp @@ -271,6 +271,12 @@ LogServiceState::initialized() return initialized_; } +bool +LogServiceState::hasSinks() +{ + return not sinks_.empty(); +} + void LogServiceState::reset() { diff --git a/src/util/log/Logger.hpp b/src/util/log/Logger.hpp index 370625890a..9e7b61eb49 100644 --- a/src/util/log/Logger.hpp +++ b/src/util/log/Logger.hpp @@ -267,6 +267,14 @@ class LogServiceState { [[nodiscard]] static bool initialized(); + /** + * @brief Whether the LogService has any sink. If there is no sink, logger will not log messages anywhere. + * + * @return true if the LogService has at least one sink + */ + [[nodiscard]] static bool + hasSinks(); + /** * @brief Reset the logging service to uninitialized state. */