I am using a macro to do simple logging on different platforms. Here’s some of what I use on android:
#include <android/log.h>
#define __ENGINE_LOG_INFO(msg, argptr) __android_log_vprint(ANDROID_LOG_INFO, __ENGINE_LOG_TAG, msg, argptr);
And here’s the corresonding I’ve tried on windows:
#elif defined _WIN32 || _WIN64
#include <stdarg.h>
#include <stdio.h>
#define __ENGINE_LOG_INFO(msg, argptr) printf ("%s:%s",__ENGINE_LOG_TAG,"DEBUG:"); printf(msg, argptr); printf("\n");
The macro is invoked in this function:
void LogManagerImpl::LogInfo(const char* msg, ...)
{
va_list argptr;
va_start(argptr, msg);
__ENGINE_LOG_INFO(msg, argptr);
va_end(argptr);
}
For example, I use it like this:
engine->GetLogger()->LogInfo("TEST: MemoryManagerTest:AllocateWithMemPool: Loop time: %d msec", timeStop - timeStart);
This works fine on Android, but for some reason it seems to print bogus values in Windows (it is the exact same value everytime – a very big value). I am starting to think it looks like an address, but I’m not sure why its not working. Any ideas?
You want to use
vprintf(msg, argptr);rather thanprintf(msg, argptr);in your windows version. Thevprintf()function was designed to work with ava_listtype as the container for the actual argument values that will be matched against the values indicated in the input character string, where-asprintf()was not.