开发者

Pantheios logging in C++ DLL

开发者 https://www.devze.com 2023-02-06 13:50 出处:网络
Here is scenario: I have testApp.cpp that has main function. And this testApp.cpp uses misc.dll and common.dll library.

Here is scenario:

I have testApp.cpp that has main function. And this testApp.cpp uses misc.dll and common.dll library.

I would like to create a log to file rather than to console.

So in testApp.cpp main() function, I use the following:

pantheios::pantheios_init();
pantheios_be_file_setFilePath("mylogfile.log");
pantheios::log_NOT开发者_JS百科ICE(" START TESTAPP");

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

This WILL create mylogfile.log file with content 'START TESTAPP'

NOW THE PROBLEM:

I would also like to adding logging from misc.dll and common.dll to mylogfile.log. In other words, if I add log in testMiscfunction() in misc.dll, I would like that log from testMiscfunction() to be written to mylogfile.log. And of course, same things with common.dll.

Now here is sample of DLL Entry for misc.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;

}

So now in

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

So "I am testMiscFunction" is not being written to mylogfile.txt Question is: Why? What need to be done.

Thanks....


The DLLs should link to Pantheios dynamically, so they'll use the same data. In this case you don't need to call Pantheios init/uninit functions from the DLL entry point (which is probably a bad idea anyway).

0

精彩评论

暂无评论...
验证码 换一张
取 消