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,3 +1,31 @@
#pragma once
#include <cstdint>
void Log(const char *format, ...);
#define LOG(fmt, ...) Log(ELogType::Log, __FILE__, __LINE__, fmt, ##__VA_ARGS__)
#define LOG_WARN(fmt, ...) Log(ELogType::Warn, __FILE__, __LINE__, fmt, ##__VA_ARGS__)
#define LOG_ERROR(fmt, ...) Log(ELogType::Error, __FILE__, __LINE__, fmt, ##__VA_ARGS__)
#define LOG_ONCE(fmt, ...) \
if (!WasLogged(ELogType::Log, __FILE__, __LINE__, fmt)) \
{ \
Log(ELogType::Log, __FILE__, __LINE__, fmt, ##__VA_ARGS__); \
}
#define WARN_ONCE(fmt, ...) \
if (!WasLogged(ELogType::Warn, __FILE__, __LINE__, fmt)) \
{ \
Log(ELogType::Warn, __FILE__, __LINE__, fmt, ##__VA_ARGS__); \
}
#define ERROR_ONCE(fmt, ...) \
if (!WasLogged(ELogType::Error, __FILE__, __LINE__, fmt)) \
{ \
Log(ELogType::Error, __FILE__, __LINE__, fmt, ##__VA_ARGS__); \
}
enum class ELogType
{
Log,
Warn,
Error,
};
void Log(ELogType logType, const char* file, uint32_t line, const char* format, ...);
bool WasLogged(ELogType logType, const char* file, uint32_t line, const char* format);