logging macros

This commit is contained in:
Asuro
2025-02-28 20:53:43 +01:00
parent 136a0e09a9
commit b0c80c1bbb
10 changed files with 139 additions and 59 deletions

View File

@@ -1,16 +1,38 @@
#include "Log.h"
#include "bx/handlealloc.h"
#include "bx/hash.h"
#include <bx/string.h>
#include <debugapi.h>
namespace
{
char LineBuffer[1024]{0};
char LineBuffer[1024]{0};
char OutBuffer[1024]{0};
bx::HandleHashMapT<1024> OnceMap;
} // namespace
void Log(ELogType logType, const char* file, uint32_t line, const char* format, ...)
{
va_list args;
va_start(args, format);
bx::snprintf(LineBuffer, sizeof(LineBuffer), "%s\n", format);
bx::vprintf(LineBuffer, args);
bx::vsnprintf(OutBuffer, sizeof(OutBuffer), LineBuffer, args);
va_end(args);
OutputDebugStringA(OutBuffer);
}
void Log(const char *format, ...)
bool WasLogged(ELogType logType, const char* file, uint32_t line, const char* format)
{
va_list args;
va_start(args, format);
bx::snprintf(LineBuffer, sizeof(LineBuffer), "%s\n", format);
bx::vprintf(LineBuffer, args);
va_end(args);
bx::HashCrc32 hasher;
hasher.begin();
hasher.add(file);
hasher.add(line);
hasher.add(logType);
hasher.add(format);
uint32_t hash = hasher.end();
if (OnceMap.find(hash) != bx::kInvalidHandle) return true;
OnceMap.insert(hash, {});
return false;
}