[英]How to start and shutdown spdlog multiple times in the same program?
我正在使用 spdlog 在 Visual Studio 中運行托管和非托管代碼的日志。 出於這個原因,我編寫了在幕后使用 spdlog 的 shell 類。
但是,我的單元測試遇到了問題。 我的單元測試在單個可執行文件中運行,因此我需要多次停止和重新啟動 spdlog 記錄器和日志文件。
我該怎么做? 我在類中使用此代碼當前在 Windows DLL 中啟動 spdlog 實例:
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;
}
實際上,我從 spdlog 的創建者那里得到了這個問題的單一答案。
從如何在同一程序中關閉和重新啟動? 關機:
void Shutdown()
{
spdlog::drop("Logger");
delete _instance;
}
然后您可以再次執行上面的創建過程。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.