Files
Bigfoot/Bigfoot/Sources/Utils/Log/Log.cpp
Romain BOULLARD 902ef87e1d
Some checks failed
Bigfoot / Build & Test Debug with ./ConanProfiles/clang (Unity Build: OFF) (push) Successful in 5m47s
Bigfoot / Build & Test Debug with ./ConanProfiles/clang_asan (Unity Build: OFF) (push) Has been cancelled
Bigfoot / Build & Test Debug with ./ConanProfiles/clang_asan (Unity Build: ON) (push) Has been cancelled
Bigfoot / Build & Test RelWithDebInfo with ./ConanProfiles/clang (Unity Build: OFF) (push) Has been cancelled
Bigfoot / Build & Test RelWithDebInfo with ./ConanProfiles/clang (Unity Build: ON) (push) Has been cancelled
Bigfoot / Build & Test RelWithDebInfo with ./ConanProfiles/clang_asan (Unity Build: OFF) (push) Has been cancelled
Bigfoot / Build & Test RelWithDebInfo with ./ConanProfiles/clang_asan (Unity Build: ON) (push) Has been cancelled
Bigfoot / Build & Test Release with ./ConanProfiles/clang (Unity Build: OFF) (push) Has been cancelled
Bigfoot / Build & Test Release with ./ConanProfiles/clang (Unity Build: ON) (push) Has been cancelled
Bigfoot / Build & Test Release with ./ConanProfiles/clang_asan (Unity Build: OFF) (push) Has been cancelled
Bigfoot / Build & Test Release with ./ConanProfiles/clang_asan (Unity Build: ON) (push) Has been cancelled
Bigfoot / Clang Format Checks (push) Has been cancelled
Bigfoot / Build & Test Debug with ./ConanProfiles/clang (Unity Build: ON) (push) Has been cancelled
Environment for tests
2026-05-16 19:56:54 +02:00

124 lines
3.4 KiB
C++

/*******************************************************************
* \file Log.cpp
*
* \author Romain BOULLARD
* \date October 2025
*********************************************************************/
#include <Utils/Log/Log.hpp>
#if defined BIGFOOT_NOT_OPTIMIZED
namespace Bigfoot
{
Log::Log()
{
m_sinks[static_cast<std::size_t>(Flat::LogSinkType::Console)] =
quill::Frontend::create_or_get_sink<quill::ConsoleSink>(
std::string {Flat::EnumNameLogSinkType(Flat::LogSinkType::Console)});
}
/****************************************************************************************/
void Log::Start()
{
quill::Backend::start();
}
/****************************************************************************************/
void Log::Stop()
{
Flush();
quill::Backend::stop();
}
/****************************************************************************************/
quill::Logger* Log::RegisterLogger(const LoggerInfo& p_loggerInfo)
{
quill::Logger* logger = quill::Frontend::create_or_get_logger(
p_loggerInfo.m_name,
m_sinks[static_cast<std::size_t>(Flat::LogSinkType::Console)]);
SetLoggerLevel(p_loggerInfo);
return logger;
}
/****************************************************************************************/
void Log::UnregisterLogger(const LoggerInfo& p_loggerInfo)
{
if (quill::Logger* logger = quill::Frontend::get_logger(p_loggerInfo.m_name))
{
quill::Frontend::remove_logger_blocking(logger);
}
}
/****************************************************************************************/
quill::Logger* Log::GetLogger(const LoggerInfo& p_loggerInfo)
{
return quill::Frontend::get_logger(p_loggerInfo.m_name);
}
/****************************************************************************************/
void Log::ChangeLoggerLogLevel(LoggerInfo& p_loggerInfo, const Flat::LogLevel p_level)
{
p_loggerInfo.m_level = p_level;
SetLoggerLevel(p_loggerInfo);
}
/****************************************************************************************/
void Log::SetLoggerLevel(const LoggerInfo& p_loggerInfo)
{
constexpr auto logLevelToQuillLogLevel = [](const Flat::LogLevel p_level) constexpr -> quill::LogLevel
{
switch (p_level)
{
case Flat::LogLevel::Debug:
return quill::LogLevel::Debug;
case Flat::LogLevel::Trace:
return quill::LogLevel::TraceL3;
case Flat::LogLevel::Info:
return quill::LogLevel::Info;
case Flat::LogLevel::Warn:
return quill::LogLevel::Warning;
case Flat::LogLevel::Error:
return quill::LogLevel::Error;
case Flat::LogLevel::Critical:
return quill::LogLevel::Critical;
}
return quill::LogLevel::TraceL3;
};
if (quill::Logger* logger = GetLogger(p_loggerInfo))
{
logger->set_log_level(logLevelToQuillLogLevel(p_loggerInfo.m_level));
}
}
/****************************************************************************************/
void Log::Flush()
{
for (quill::Logger* logger: quill::Frontend::get_all_loggers())
{
logger->flush_log();
}
}
/****************************************************************************************/
Log::~Log()
{
for (quill::Logger* logger: quill::Frontend::get_all_loggers())
{
quill::Frontend::remove_logger(logger);
}
}
} // namespace Bigfoot
#endif