I'm using spdlog to run logs for both managed and unmanaged code in Visual Studio. For that reason I've written shell classes that use spdlog under the hood.
However, I'm running into problems with my unit tests. My unit tests run in a single executable and so I need to stop and restart spdlog loggers and logfiles multiple times.
How do I do this? I'm using this code in a class to currently start instances of spdlog in a Windows DLL:
private:
API static std::mutex _mutex;
API static std::shared_ptr<spdlog::logger> _instance;
static std::shared_ptr<spdlog::logger> Instance()
{
std::unique_lock<std::mutex> lck(_mutex, std::defer_lock);
lck.lock();
if (_instance == nullptr)
{
_instance = spdlog::rotating_logger_mt("Logger", "EXO", 1024 * 1024 * 5, 4, true);
}
lck.unlock();
return _instance;
}
I got this answer from spdlog's creator.
From How to shutdown and restart in the same program? to shutdown:
void Shutdown()
{
spdlog::drop("Logger");
delete _instance;
}
Then you can go through the creation process above again.