ITALog.cpp 1.25 KB
Newer Older
Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
#include <ITALog.h>

#include <ITACriticalSection.h>

#include <stdarg.h>
#include <stdio.h>
#include <string>

#ifdef WIN32
#include <windows.h>
#endif

#define DEBUG_PRINTF_BUFSIZE 16384

static ITACriticalSection g_csDebugPrintf;
static char g_pszDebugPrintfBuf[DEBUG_PRINTF_BUFSIZE];


void italog_printf(const char* pszModuleName, int iFlags, const char* format ...) {

	std::string sCombinedPreamble = "";
	if (iFlags & (ITALOG_MODULENAME + ITALOG_SHORTNAME)) {
		sCombinedPreamble += pszModuleName;
		sCombinedPreamble += ": ";
	}

	// Source: VADebug by fwe
	va_list args;
	va_start(args, format);
#ifdef WIN32
	printf_s("%s", sCombinedPreamble.c_str());
#else
	printf("%s", sCombinedPreamble.c_str());
#endif
	vfprintf(stdout, format, args);
	va_end(args);

	return;
};

#ifdef WIN32
void italog_msvc(const char* pszModuleName, int iFlags, const char* format ...) {
	g_csDebugPrintf.enter();

	int pos = 0;
	if (iFlags & (ITALOG_MODULENAME + ITALOG_SHORTNAME))
		pos = sprintf_s(g_pszDebugPrintfBuf, DEBUG_PRINTF_BUFSIZE, "%s: ", pszModuleName);

	va_list args;
	va_start(args, format);
	vsprintf_s(g_pszDebugPrintfBuf+pos, DEBUG_PRINTF_BUFSIZE-pos, format, args);
	va_end(args);

	OutputDebugStringA(g_pszDebugPrintfBuf);
	g_csDebugPrintf.leave();

	return;
}
#endif