Enable log information
This commit is contained in:
@@ -14,6 +14,11 @@
|
||||
#include "base64.h"
|
||||
#include <spdlog/sinks/base_sink.h>
|
||||
#include <winnt.h>
|
||||
#include <atomic>
|
||||
#include <chrono>
|
||||
#include <filesystem>
|
||||
#include <system_error>
|
||||
#include <cstdlib>
|
||||
|
||||
#define MAX_CUSTOMER_NAME_LEN 100
|
||||
#define FEATURE_1 0x1
|
||||
@@ -2963,4 +2968,45 @@ namespace ANSCENTER
|
||||
return logger.Release();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
// Runtime DebugView toggle — gates ANS_DBG without requiring a rebuild.
|
||||
//
|
||||
// Precedence per poll: env var ANSCENTER_DBGVIEW wins over the sentinel file.
|
||||
// Poll interval is 2 s, so toggling takes effect within that window. Hot-path
|
||||
// cost on a cache hit is a single relaxed atomic load + branch.
|
||||
// ============================================================================
|
||||
extern "C" ANSLICENSE_API int ANSCENTER_IsDebugViewEnabled(void) {
|
||||
using clock = std::chrono::steady_clock;
|
||||
static std::atomic<int> s_enabled{0};
|
||||
static std::atomic<long long> s_nextCheckTick{0};
|
||||
|
||||
const long long now = clock::now().time_since_epoch().count();
|
||||
const long long next = s_nextCheckTick.load(std::memory_order_relaxed);
|
||||
if (now < next) {
|
||||
return s_enabled.load(std::memory_order_relaxed);
|
||||
}
|
||||
|
||||
int enabled = 0;
|
||||
const char* env = std::getenv("ANSCENTER_DBGVIEW");
|
||||
if (env && env[0] == '1' && env[1] == '\0') {
|
||||
enabled = 1;
|
||||
} else if (env && env[0] == '0' && env[1] == '\0') {
|
||||
enabled = 0;
|
||||
} else {
|
||||
#ifdef _WIN32
|
||||
const wchar_t* kSentinel = L"C:\\ProgramData\\ANSCENTER\\ansvisdebugview.txt";
|
||||
#else
|
||||
const char* kSentinel = "/tmp/ansvisdebugview.txt";
|
||||
#endif
|
||||
std::error_code ec;
|
||||
enabled = std::filesystem::exists(kSentinel, ec) ? 1 : 0;
|
||||
}
|
||||
|
||||
s_enabled.store(enabled, std::memory_order_relaxed);
|
||||
const long long deadline = now +
|
||||
std::chrono::duration_cast<clock::duration>(std::chrono::seconds(2)).count();
|
||||
s_nextCheckTick.store(deadline, std::memory_order_relaxed);
|
||||
return enabled;
|
||||
}
|
||||
Reference in New Issue
Block a user