Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/util/Assert.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
6 changes: 6 additions & 0 deletions src/util/log/Logger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,12 @@ LogServiceState::initialized()
return initialized_;
}

bool
LogServiceState::hasSinks()
{
return not sinks_.empty();
}

void
LogServiceState::reset()
{
Expand Down
8 changes: 8 additions & 0 deletions src/util/log/Logger.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down
Loading