You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
50 lines
1.6 KiB
50 lines
1.6 KiB
#pragma once |
|
|
|
#if !defined(GUI_DEBUG_DISABLE) |
|
|
|
#include <cstdio> |
|
#include <cstdarg> |
|
#include <cstring> |
|
|
|
namespace GuiDebugPriv { |
|
inline FILE *s_file = stderr; |
|
|
|
inline void setFile(const char *path) { |
|
if (s_file && s_file != stderr) fclose(s_file); |
|
s_file = path ? fopen(path, "a") : nullptr; |
|
if (!s_file) s_file = stderr; |
|
} |
|
} |
|
|
|
inline void guiDebugFile(const char *path) { GuiDebugPriv::setFile(path); } |
|
|
|
inline void guiDebugLog(char lvl, const char *file, int line, |
|
const char *func, const char *fmt, ...) { |
|
const char *base = strrchr(file, '/'); |
|
if (!base) base = strrchr(file, '\\'); |
|
if (GuiDebugPriv::s_file != stderr) |
|
fprintf(GuiDebugPriv::s_file, "[1] "); |
|
fprintf(GuiDebugPriv::s_file, "[%c] %s:%d %s(): ", |
|
lvl, base ? base + 1 : file, line, func); |
|
va_list ap; |
|
va_start(ap, fmt); |
|
vfprintf(GuiDebugPriv::s_file, fmt, ap); |
|
va_end(ap); |
|
fprintf(GuiDebugPriv::s_file, "\n"); |
|
fflush(GuiDebugPriv::s_file); |
|
} |
|
|
|
#define GUI_ERROR(fmt, ...) guiDebugLog('E', __FILE__, __LINE__, __func__, fmt, ##__VA_ARGS__) |
|
#define GUI_WARN(fmt, ...) guiDebugLog('W', __FILE__, __LINE__, __func__, fmt, ##__VA_ARGS__) |
|
#define GUI_INFO(fmt, ...) guiDebugLog('I', __FILE__, __LINE__, __func__, fmt, ##__VA_ARGS__) |
|
#define GUI_DEBUG(fmt, ...) guiDebugLog('D', __FILE__, __LINE__, __func__, fmt, ##__VA_ARGS__) |
|
|
|
#else |
|
|
|
inline void guiDebugFile(const char*) {} |
|
#define GUI_ERROR(...) ((void)0) |
|
#define GUI_WARN(...) ((void)0) |
|
#define GUI_INFO(...) ((void)0) |
|
#define GUI_DEBUG(...) ((void)0) |
|
|
|
#endif
|
|
|