I have two printf style debug logging functions (DebuglogfA
, DebuglogfB
). Both operate the same way but one of the logging functions takes a logging level as a parameters and ignores low level debug messages.
Currently I duplicate the code for each of these functions but I would like DebuglogfB to be able to call DebuglogfA if the debug level is high enough without having to create a temporary buffer in DebuglogfB.
void DebuglogfA( const char *lpszText, ...)
{
//Initialize variable argument list
va_list argList;
va_start(argList, lpszText);
char buffer[1024];
unsigned short length = snprintf_s(buffer, 1024, "[%d] ", CTime::GetCurrentTimeInSec() );
length += vsnprintf (buffer+length, 1024 - length, lpszText, argList );
LogSend( buffer, length );
}
void DebuglogfB ( const unsigned int level, const char *lpszText, ... )
{
if( level < 50 ) {
return; // To low to report.
}
//Initialize variable argument list
va_list argList;
va_start(argList, lpszText);
char buffer[1024];
unsigned short length = snprintf_s(buffer, 1024, "[%d] ", CTime::GetCurrentTimeInSec() );
length += vsnprintf (buffer+length, 1024 - length, lpszText, argList );
LogSend( buffer, length );
}
My question is:
How do I get function DebuglogfB to call DebuglogfA without creating a buffer for the message in DebuglogfB?
You could create a new function DebuglogfV
which has const char *lpszText
and va_list argList
as parameters, and then let DebuglogfA
and DebuglogfB
call it to perform the actual logging.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With