strip sensitive information from logs

This commit is contained in:
2026-04-26 07:35:30 +10:00
parent f81737ffc6
commit da94e7f6da
6 changed files with 225 additions and 51 deletions

View File

@@ -39,36 +39,25 @@ extern "C" {
ANSLICENSE_API void ANSLogger_LogInfo (const char* src, const char* msg, const char* file, int line);
ANSLICENSE_API void ANSLogger_LogError(const char* src, const char* msg, const char* file, int line);
ANSLICENSE_API void ANSLogger_LogFatal(const char* src, const char* msg, const char* file, int line);
// DebugView choke point shared by ANS_DBG and ANSLIB_DBG. Strips noise
// path prefixes before emitting to OutputDebugStringA + stderr.
ANSLICENSE_API void ANSCENTER_DebugLog(const char* preformattedLine);
}
// ANS_DBG: Debug logging macro for DebugView (OutputDebugStringA on Windows).
// Usage: ANS_DBG("MyModule", "value=%d ptr=%p", val, ptr);
// Output: [MyModule] value=42 ptr=0x1234
// NOTE: We avoid #include <windows.h> here to prevent winsock.h/winsock2.h
// conflicts. Instead, forward-declare OutputDebugStringA directly.
#if ANSCORE_DEBUGVIEW && defined(_WIN32)
extern "C" __declspec(dllimport) void __stdcall OutputDebugStringA(const char* lpOutputString);
// Emit to BOTH DebugView (OutputDebugStringA) AND stderr so console apps
// (ANSCV-UnitTest, ANSLPR-UnitTest, ANSUtilities_test, etc.) show the message
// without needing to attach DebugView. fputs + fflush keeps lines atomic even
// when multiple threads log concurrently.
//
// Routes through ANSCENTER_DebugLog so noise path prefixes (e.g. the
// ProgramData profile dir) are stripped centrally before emit. The macro just
// formats on the caller's stack and hands off the buffer.
#if ANSCORE_DEBUGVIEW
#define ANS_DBG(tag, fmt, ...) do { \
if (ANSCENTER_IsDebugViewEnabled()) { \
char _ans_dbg_buf[1024]; \
snprintf(_ans_dbg_buf, sizeof(_ans_dbg_buf), "[" tag "] " fmt "\n", ##__VA_ARGS__); \
OutputDebugStringA(_ans_dbg_buf); \
fputs(_ans_dbg_buf, stderr); \
fflush(stderr); \
} \
} while(0)
#elif ANSCORE_DEBUGVIEW
// Non-Windows: stderr only.
#define ANS_DBG(tag, fmt, ...) do { \
if (ANSCENTER_IsDebugViewEnabled()) { \
char _ans_dbg_buf[1024]; \
snprintf(_ans_dbg_buf, sizeof(_ans_dbg_buf), "[" tag "] " fmt "\n", ##__VA_ARGS__); \
fputs(_ans_dbg_buf, stderr); \
fflush(stderr); \
ANSCENTER_DebugLog(_ans_dbg_buf); \
} \
} while(0)
#else