跨平台日志宏在 Windows 上不起作用
我正在使用宏在不同平台上进行简单的日志记录。这是我在 android 上使用的一些内容:
#include <android/log.h>
#define __ENGINE_LOG_INFO(msg, argptr) __android_log_vprint(ANDROID_LOG_INFO, __ENGINE_LOG_TAG, msg, argptr);
这是我在 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");
在此函数中调用宏:
void LogManagerImpl::LogInfo(const char* msg, ...)
{
va_list argptr;
va_start(argptr, msg);
__ENGINE_LOG_INFO(msg, argptr);
va_end(argptr);
}
例如,我这样使用它:
engine->GetLogger()->LogInfo("TEST: MemoryManagerTest:AllocateWithMemPool: Loop time: %d msec", timeStop - timeStart);
这在 Android 上运行良好,但由于某种原因,它似乎在 Windows 中打印虚假值(每次都是完全相同的值 - 一个非常大的值)。我开始认为它看起来像一个地址,但我不确定为什么它不起作用。有什么想法吗?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
更多
发布评论
评论(1)
您希望在 Windows 版本中使用
vprintf(msg, argptr);
而不是printf(msg, argptr);
。vprintf()
函数设计为使用va_list
类型作为实际参数值的容器,这些值将与输入字符串中指示的值进行匹配,其中-asprintf()
不是。You want to use
vprintf(msg, argptr);
rather thanprintf(msg, argptr);
in your windows version. Thevprintf()
function was designed to work with ava_list
type 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.