VMware {code} Community
arent_t
Hot Shot
Hot Shot

VixDiskLibGenericLogFunc

For multithreaded applications you suppose to implement your own logging, how do you do this ? Can somebody provide an example ?

Many thanks,

Tom

0 Kudos
1 Reply
admin
Immortal
Immortal

#define VDDK_LOG_FILE "c:
temp
LogFunc.log"

#define VDDK_WARN_FILE "c:
temp
WarnFunc.log"

#define VDDK_PANIC_FILE "c:
temp
PanicFunc.log"

CRITICAL_SECTION g_arrCriticalSections[3];

somewhere at the beginning ...

::InitializeCriticalSection(&g_arrCriticalSections[0]);

::InitializeCriticalSection(&g_arrCriticalSections[1]);

::InitializeCriticalSection(&g_arrCriticalSections[2]);

somewhere at the end...

::DeleteCriticalSection(&g_arrCriticalSections[0]);

::DeleteCriticalSection(&g_arrCriticalSections[1]);

::DeleteCriticalSection(&g_arrCriticalSections[2]);

void LogFunc(const char *format, va_list info)

{

FILE* stream;

errno_t err;

::EnterCriticalSection(&g_arrCriticalSections[0]);

if((err = fopen_s( &stream, VDDK_LOG_FILE, "a" )) !=0 )

std::cout<<"The file "<<VDDK_LOG_FILE<<" was not opened."<<std::endl;

else

{

vfprintf(stream, format, info);

fclose(stream);

}

::LeaveCriticalSection(&g_arrCriticalSections[0]);

}

void WarnFunc(const char *format, va_list info)

{

FILE* stream;

errno_t err;

::EnterCriticalSection(&g_arrCriticalSections[1]);

if((err = fopen_s( &stream, VDDK_WARN_FILE, "a" )) !=0 )

std::cout<<"The file "<<VDDK_WARN_FILE<<" was not opened."<<std::endl;

else

{

vfprintf(stream, format, info);

fclose(stream);

}

::LeaveCriticalSection(&g_arrCriticalSections[1]);

}

void PanicFunc(const char *format, va_list info)

{

FILE* stream;

errno_t err;

::EnterCriticalSection(&g_arrCriticalSections[2]);

if((err = fopen_s( &stream, VDDK_PANIC_FILE, "a" )) !=0 )

std::cout<<"The file "<<VDDK_PANIC_FILE<<" was not opened."<<std::endl;

else

{

vfprintf(stream, format, info);

fclose(stream);

}

::LeaveCriticalSection(&g_arrCriticalSections[2]);

}

0 Kudos