| 123456789101112131415161718192021222324252627282930313233343536373839404142 |
- #pragma once
- #include <windows.h>
- #include <sstream>
- #include <cstdio>
- #define DEBUG_LOG_BUFFER_SIZE 1024
- #define DEBUG_LOG(msg) do { \
- std::wostringstream __oss; \
- __oss << L"[" << __func__ << L"]@" << __FILE__ << L":" << __LINE__ << L": " << msg << L"\n"; \
- OutputDebugString(__oss.str().c_str()); \
- } while(0)
- #define DEBUG_LOG_VAR(msg, val) do { \
- std::wostringstream __oss; \
- __oss << L"[" << __func__ << L"]@" << __FILE__ << L":" << __LINE__ << L": " << msg << L": " << val << L"\n"; \
- OutputDebugString(__oss.str().c_str()); \
- } while(0)
- #define DEBUG_LOG_FMT(format, ...) do { \
- wchar __logbuf[DEBUG_LOG_BUFFER_SIZE]; \
- std::swprintf(__logbuf, DEBUG_LOG_BUFFER_SIZE, format, ##__VA_ARGS__); \
- wchar __fullmsg[DEBUG_LOG_BUFFER_SIZE + 128]; \
- std::swprintf(__fullmsg, sizeof(__fullmsg), L"[%s]@%s:%d: %s\n", __func__, __FILE__, __LINE__, __logbuf); \
- OutputDebugString(__fullmsg); \
- } while(0)
- class DEBUG_LOG
- {
- public:
- static void debug_printf(const char * format, ...)
- {
- va_list args;
- va_start(args, format);
- vprintf(format, args); // 原生打印到控制台(或重定向的输出)
- char buffer[1024]; // 创建一个足够大的缓冲区来存储格式化后的字符串(可选)
- vsnprintf(buffer, sizeof(buffer), format, args); // 将格式化后的字符串存储到buffer中(可选)
- va_end(args); // 清理变量参数列表(optional)
- DEBUG_LOG(buffer);
- }
- };
|