0

I have got an MFC app comprised of one exe and two DLLs. The exe calls functions from those two DLLs. Now I am trying to add some logging by using the Pantheios logging lib.

What I want to achieve:
The exe and the two DLLs are all logging to the same log file in hard drive.

Here is what I have done:

1) Using implicit linking in main exe program:


#include "stdafx.h"

#include <pantheios/implicit_link/core.h>
#include <pantheios/implicit_link/fe.simple.h>
#include <pantheios/implicit_link/be.file.h>


#define USER_SPECIFIED_LEVEL
#ifndef USER_SPECIFIED_LEVEL
  #include <pantheios/implicit_link/fe.simple.h>
#endif

#ifdef USER_SPECIFIED_LEVEL
PANTHEIOS_CALL(int) pantheios_fe_init(void*   reserved,void**  ptoken)
{
    *ptoken = NULL;
    return 0;
}

PANTHEIOS_CALL(void) pantheios_fe_uninit(void* token)
{}

PANTHEIOS_CALL(PAN_CHAR_T const*)  pantheios_fe_getProcessIdentity  (void *  token)
{
    return PANTHEIOS_LITERAL_STRING(MY_PROGRAM_ID);
}

PANTHEIOS_CALL(int) pantheios_fe_isSeverityLogged(void* token
                                                  , int   severity
                                                  , int   backEndId)
{
    //SEV_CRITICAL=2 < SEV_ERROR=3 < SEV_WARNING=4 < SEV_INFORMATIONAL=6
    if(severity <= pantheios::SEV_INFORMATIONAL)
        return 1;//allow output for anything above information lvl
    return 0;
}

#endif

In the main exe program where I need to add logging I use (after looked this link in SO talking about PANTHEIOS_BE_FILE_F_SHARE_ON_WINDOWS):

pantheios_be_file_setFilePath(PSTR("C:\\TestLog.log"),**PANTHEIOS_BE_FILE_F_SHARE_ON_WINDOWS**, 0, PANTHEIOS_BEID_ALL);
        pantheios::log_NOTICE(PSTR("process id: ["), pantheios::processId, PSTR("]"));
    pantheios::log_NOTICE(PSTR("thread id: ["), pantheios::threadId, PSTR("]"));
    pantheios::log_INFORMATIONAL(PSTR("testing log messagse"));

This works fine, and I can get logging in c:\TestLog.log file as expected. However, I cannot get logging at all in those two DLLs, it simply gives erros for each logging call:

    pantheios::log_INFORMATIONAL(PSTR("testing message"));

saying the token is emtpy, so I Googled and found a solution:

2) I need to call:

pantheios::init();

for each DLL initialization inside their DllMain function. This way, there is no more "empty token" error when I try to log in the DLL, but still there's nothing logged by the DLLs in the log file (again, the main exe program is fine).

3) I tweaked stuff a bit and I have to change the logging file names in the DLL loggings so they all log to different files:

DLL #1:

pantheios_be_file_setFilePath(PSTR("C:\\TestLogDll1.log"),PANTHEIOS_BE_FILE_F_SHARE_ON_WINDOWS, 0, PANTHEIOS_BEID_ALL);

DLL #2:

pantheios_be_file_setFilePath(PSTR("C:\\TestLogDll2.log"),PANTHEIOS_BE_FILE_F_SHARE_ON_WINDOWS, 0, PANTHEIOS_BEID_ALL);

This way I have 3 logging files all working fine:

  • TestLog.log for the main program
  • TestLogDll1.log for DLL #1
  • TestLogDll2.log for DLL #2

But still I just cannot get both DLLs logging to the same file as the main exe does (TestLog.log).

Community
  • 1
  • 1
RoundPi
  • 5,819
  • 7
  • 49
  • 75

1 Answers1

0

To share entity or object between exe and dll, you may need to declare __declspec(dllexport) in the exe which exports them, and __declspec(dllimport) in the dll which import them.

For reference:
1) http://sourceforge.net/projects/pantheios/forums/forum/647484/topic/1639420/index/page/1
2) Use Pantheios logging framework from a dll

Community
  • 1
  • 1
wengseng
  • 1,330
  • 1
  • 14
  • 27