ITALog.cpp 1.28 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
#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;
16
static char g_pszDebugPrintfBuf[ DEBUG_PRINTF_BUFSIZE ];
Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
17 18


19 20
void italog_printf( const char* pszModuleName, int iFlags, const char* format ... )
{
Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
21 22

	std::string sCombinedPreamble = "";
23 24
	if( iFlags & ( ITALOG_MODULENAME + ITALOG_SHORTNAME ) )
	{
Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
25 26 27 28 29 30
		sCombinedPreamble += pszModuleName;
		sCombinedPreamble += ": ";
	}

	// Source: VADebug by fwe
	va_list args;
31
	va_start( args, format );
Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
32 33 34
#ifdef WIN32
	printf_s("%s", sCombinedPreamble.c_str());
#else
35
	printf( "%s", sCombinedPreamble.c_str() );
Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
36
#endif
37 38
	vfprintf( stdout, format, args );
	va_end( args );
Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
39 40 41 42 43

	return;
};

#ifdef WIN32
44 45
void italog_msvc( const char* pszModuleName, int iFlags, const char* format ... )
{
Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
46 47 48
	g_csDebugPrintf.enter();

	int pos = 0;
49 50
	if( iFlags & ( ITALOG_MODULENAME + ITALOG_SHORTNAME ) )
		pos = sprintf_s( g_pszDebugPrintfBuf, DEBUG_PRINTF_BUFSIZE, "%s: ", pszModuleName );
Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
51 52

	va_list args;
53 54 55
	va_start( args, format );
	vsprintf_s( g_pszDebugPrintfBuf + pos, DEBUG_PRINTF_BUFSIZE - pos, format, args );
	va_end( args );
Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
56

57
	OutputDebugStringA( g_pszDebugPrintfBuf );
Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
58 59 60 61
	g_csDebugPrintf.leave();

	return;
}
62 63

#endif