Enable log information

This commit is contained in:
2026-04-21 12:09:24 +10:00
parent 7e772f76bc
commit 00f6e2f852
5 changed files with 247 additions and 40 deletions

View File

@@ -1,20 +1,40 @@
#ifndef ANSLICENSE_H
#define ANSLICENSE_H
#ifdef ANSLICENSE_EXPORTS
#define ANSLICENSE_API __declspec(dllexport)
#else
#define ANSLICENSE_API __declspec(dllimport)
#endif
// ============================================================================
// Global debug toggle for DebugView (DbgView) logging.
// Define ANSCORE_DEBUGVIEW=1 to enable verbose OutputDebugStringA logging
// across all ANSCORE modules (ANSCV, ANSODEngine, TensorRT engine, etc.).
// Set to 0 for production builds to eliminate all debug output overhead.
// DebugView (DbgView) logging toggle.
//
// ANS_DBG is compiled into every build; visibility is chosen at runtime by
// ANSCENTER_IsDebugViewEnabled() — a cached check (~2 s) that reads:
// 1. env var ANSCENTER_DBGVIEW (="1" forces on, ="0" forces off), else
// 2. existence of C:\ProgramData\ANSCENTER\ansvisdebugview.txt (Windows) or
// /tmp/ansvisdebugview.txt (POSIX).
//
// Drop the sentinel file to turn logging on; delete it to turn it off. No
// rebuild, no restart — takes effect within ~2 s. ACLs on ProgramData are
// world-writable by default so any user can toggle.
//
// Hard kill-switch: compile with -DANSCORE_DEBUGVIEW=0 to strip ANS_DBG to
// ((void)0) — use only when even the atomic-load cost is unacceptable.
// ============================================================================
#ifndef ANSCORE_DEBUGVIEW
#define ANSCORE_DEBUGVIEW 1 // 1 = enabled (debug), 0 = disabled (production)
#define ANSCORE_DEBUGVIEW 1 // 1 = runtime-gated (default), 0 = hard-off (stripped)
#endif
// Runtime gate. Implemented in ANSLicense.cpp. Returns non-zero when logging
// should be emitted. Cheap on the hot path: one atomic load + branch; the
// filesystem check runs at most once per ~2 s.
extern "C" ANSLICENSE_API int ANSCENTER_IsDebugViewEnabled(void);
// 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
// When ANSCORE_DEBUGVIEW=0, compiles to nothing (zero overhead).
// NOTE: We avoid #include <windows.h> here to prevent winsock.h/winsock2.h
// conflicts. Instead, forward-declare OutputDebugStringA directly.
#if ANSCORE_DEBUGVIEW && defined(_WIN32)
@@ -24,30 +44,28 @@ extern "C" __declspec(dllimport) void __stdcall OutputDebugStringA(const char* l
// without needing to attach DebugView. fputs + fflush keeps lines atomic even
// when multiple threads log concurrently.
#define ANS_DBG(tag, fmt, ...) do { \
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); \
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 { \
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); \
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); \
} \
} while(0)
#else
#define ANS_DBG(tag, fmt, ...) ((void)0)
#endif
#ifdef ANSLICENSE_EXPORTS
#define ANSLICENSE_API __declspec(dllexport)
#else
#define ANSLICENSE_API __declspec(dllimport)
#endif
#pragma once
#include <stdlib.h>