c++ - Trying to combine two similar printf style debug messages in to a single function -


i have 2 printf style debug logging functions (debuglogfa, debuglogfb). both operate same way 1 of logging functions takes logging level parameters , ignores low level debug messages.

currently duplicate code each of these functions debuglogfb able call debuglogfa if debug level high enough without having create 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; // low 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 function debuglogfb call debuglogfa without creating buffer message in debuglogfb?

you create new function debuglogfv has const char *lpsztext , va_list arglist parameters, , let debuglogfa , debuglogfb call perform actual logging.


Comments

Popular posts from this blog

javascript - Iterate over array and calculate average values of array-parts -

iphone - Using nested NSDictionary with Picker -

objective c - Newbie question -multiple parameters -