c++ - Pantheios 登录 C++ DLL

标签 c++ logging

这是场景:

我有 testApp.cpp 具有 main 功能。而这个testApp.cpp 使用了misc.dllcommon.dll 库。

我想创建一个日志到文件而不是控制台。

所以在 testApp.cpp main() 函数中,我使用以下内容:

pantheios::pantheios_init();
pantheios_be_file_setFilePath("mylogfile.log");
pantheios::log_NOTICE(" START TESTAPP");

// Call function from misc.dll and common.dll
pantheios::log_NOTICE(" END TESTAPP ");
pantheios_be_file_setFilePath(NULL);

这将创建内容为“START TESTAPP”的 mylogfile.log 文件

现在是问题:

我还想将日志记录从 misc.dll 和 common.dll 添加到 mylogfile.log。 换句话说,如果我在 misc.dll 中添加登录 testMiscfunction(),我希望该日志来自 testMiscfunction() 将写入 mylogfile.log。 当然,common.dll 也是如此。

现在这里是 misc.dll 的 DLL 入口示例

#include "pantheios/pantheios.hpp" 
#include "pantheios/backends/bec.file.h" 
#include "pantheios/implicit_link/core.h"
#include "pantheios/implicit_link/be.file.h"

extern "C" const char PANTHEIOS_FE_PROCESS_IDENTITY[] = "MISC_DLL"; 

BOOL APIENTRY DllMain( HANDLE hModule, 
                       DWORD  ul_reason_for_call, 
                       LPVOID lpReserved
            )
{
    switch (ul_reason_for_call)
    {
        case DLL_PROCESS_ATTACH:
            pantheios::pantheios_init();
            break;

        case DLL_THREAD_ATTACH:
            break;


        case DLL_THREAD_DETACH:
            break;


        case DLL_PROCESS_DETACH:
            pantheios::pantheios_uninit();
            break;
    }
    return TRUE;

}

所以现在在

testMiscFunction() { pantheios::log_NOTICE("I am testMiscFunction"); } 

所以“我是 testMiscFunction”没有被写入 mylogfile.txt 问题是:为什么?需要做什么。

谢谢....

最佳答案

DLL 应动态链接到 Pantheios,因此它们将使用相同的数据。在这种情况下,您不需要从 DLL 入口点调用 Pantheios init/uninit 函数(无论如何这可能是个坏主意)。

关于c++ - Pantheios 登录 C++ DLL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4799579/

相关文章:

C++11内存模型: why can't compiler move statements across load() operations during optimization?

c++ - "No instance of overload function"

C++ - 遍历 map 的 map

logging - 在Powershell脚本中使用滚动日志文件收集性能计数器

python - 将每个请求的上下文添加到 Python 中的日志记录

java - log4j配置文件和jar应用程序

c++ - 尝试创建 CAS 模板

c++ - 是否可以在 visual studio 2010 中编译 ffmpeg?

C++ - 无法使用 msys2 和 cmake 链接到 Boost::logger

logging - 集中记录的最佳实践是什么?