TombEngine/TR5Main/Game/debug/debug.cpp

60 lines
1.3 KiB
C++
Raw Normal View History

2021-08-03 15:08:43 +01:00
#include "framework.h"
#include <spdlog.h>
#include <spdlog/sinks/stdout_color_sinks.h>
#include <spdlog/sinks/basic_file_sink.h>
void InitTENLog()
{
// "true" means that we create a new log file each time we run the game
auto file_sink = std::make_shared<spdlog::sinks::basic_file_sink_mt>("Logs/TENLog.txt", true);
std::shared_ptr<spdlog::logger> logger;
if constexpr (DebugBuild)
{
// Set the file and console log targets
auto console_sink = std::make_shared<spdlog::sinks::stdout_color_sink_mt>();
logger = std::make_shared<spdlog::logger>(std::string{ "multi_sink" }, spdlog::sinks_init_list{file_sink, console_sink });
}
else
{
logger = std::make_shared<spdlog::logger>(std::string{ "multi_sink" }, file_sink);
}
spdlog::initialize_logger(logger);
logger->set_level(spdlog::level::info);
logger->flush_on(spdlog::level::info);
logger->set_pattern("[%Y-%b-%d %T] [%^%l%$] %v");
}
2021-08-03 15:08:43 +01:00
void TENLog(std::string_view str, LogLevel level, LogConfig config)
{
if constexpr (!DebugBuild)
2021-08-03 15:08:43 +01:00
{
if (LogConfig::Debug == config)
{
return;
}
}
auto logger = spdlog::get("multi_sink");
2021-08-03 15:08:43 +01:00
switch (level)
{
case LogLevel::Error:
logger->error(str);
break;
2021-08-03 15:08:43 +01:00
case LogLevel::Warning:
logger->warn(str);
2021-08-03 15:08:43 +01:00
break;
case LogLevel::Info:
logger->info(str);
2021-08-03 15:08:43 +01:00
break;
}
logger->flush();
}
void ShutdownTENLog()
{
spdlog::shutdown();
2021-08-03 15:08:43 +01:00
}