Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/logging/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 如何在同一程序中多次启动和关闭spdlog?_C++_Logging_C++ Cli_Spdlog - Fatal编程技术网

C++ 如何在同一程序中多次启动和关闭spdlog?

C++ 如何在同一程序中多次启动和关闭spdlog?,c++,logging,c++-cli,spdlog,C++,Logging,C++ Cli,Spdlog,我使用spdlog在VisualStudio中运行托管和非托管代码的日志。出于这个原因,我编写了在后台使用spdlog的shell类 但是,我的单元测试遇到了问题。我的单元测试在一个可执行文件中运行,因此我需要多次停止并重新启动spdlog记录器和日志文件 我该怎么做?我正在类中使用此代码来当前启动Windows DLL中的spdlog实例: private: API static std::mutex _mutex; API static std::shared_ptr<

我使用spdlog在VisualStudio中运行托管和非托管代码的日志。出于这个原因,我编写了在后台使用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;
    }
private:
API静态std::mutex\u mutex;
API静态std::共享的\u ptr\u实例;
静态std::shared_ptr实例()
{
std::unique_lock lck(_mutex,std::defer_lock);
lck.lock();
if(_instance==nullptr)
{
_instance=spdlog::rotating_logger_mt(“logger”,“EXO”,1024*1024*5,4,true);
}
lck.unlock();
返回_实例;
}

对于这个问题,我从spdlog的创建者那里得到了一个答案

从开始到关闭:

void Shutdown()
{
    spdlog::drop("Logger");
    delete _instance;
}
然后您可以再次完成上面的创建过程