如何在同一程序中多次启动和关闭 spdlog
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;
}
然后,您可以再次完成上面的创建过程。
相关文章:
- 如何创建一个空的全局类并在启动时实例化它
- spdlog标头仅与外部fmt一起使用.spdlog错误:'内部':不是'fmt'
- 即使我读取了所有内容,在FIFO上打开的QSocketNotifier也会一直启动
- 使用 std::string () const 函数启动线程或未来
- 如何修复valgrind启动时的致命错误(与libc6-dbg和libc6-dbg:i386连接)
- 将向量作为类>(值)<向量启动和向量<类>[值]有什么区别
- 如何创建线程序列以按照启动顺序执行任务?
- WINAPI 注册应用程序重新启动时不清除打开的套接字
- 在挂钩启动新线程时解除挂钩进程
- 程序无法启动,因为缺少 libmpc-3.dll
- 创建 Spdlog 异步文件记录器时遇到困难
- 从 exe 文件 (Visual Studio ) 启动时调试断言失败
- QSerialPort 在应用程序启动之前正在使用中
- 无法在 Arch Linux 中启动虚幻引擎 4
- C++关于指针和使用函数将它们启动到堆的行为究竟是什么?
- 如何使用 ctypes 停止和重新启动从 Python 运行的C++代码
- 程序在使用 system() 启动另一个可执行文件时停止
- Qt 和 Android - 如何使用 Qandroidjniobject 启动相机
- 通过复制包含目录的内容来安装 spdlog
- 如何在同一程序中多次启动和关闭 spdlog