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

时间:2016-05-20 22:25:50

标签: c++ logging c++-cli spdlog

我正在使用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;
    }

1 个答案:

答案 0 :(得分:3)

尽管由于这个问题是以意见为基础而关闭了投票,但实际上我从spdlog的创建者那里得到了这个问题的单一答案。

How to shutdown and restart in the same program?到关机:

findLink = driver.find_elements_by_id('find-label');
for links in findLink:
    print links.click();
    # do whatever you want and navigate back to access the next find-label element

然后你可以再次完成上面的创作过程。

相关问题