From c114c3f689fcf00dc8b6588435e75b2fb870b30f Mon Sep 17 00:00:00 2001 From: Andrei Date: Fri, 3 Jul 2026 14:28:03 +0200 Subject: [PATCH 1/2] docs(native-examples): demonstrate EnableFileLogging in windows-monitor MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Enable the collector's built-in async file logger (#1221) in the windows-monitor example: call EnableFileLogging before Start so a run also writes the NLog-parity DataCollector_.txt (+ _error_) files alongside the stderr callback. Directory defaults to ./Logs, overridable via HSM_LOG_DIR. Exercises the collector's built-in file sink (the aggregator's logging feature) in a runnable example — distinct from the HSM agent, which supplies its own file logger via SetLogger. Example-only, no library change. Co-Authored-By: Claude Opus 4.8 --- .../collector/examples/windows-monitor/main.cpp | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/native/collector/examples/windows-monitor/main.cpp b/src/native/collector/examples/windows-monitor/main.cpp index 8aa500468..ac3ed8d7d 100644 --- a/src/native/collector/examples/windows-monitor/main.cpp +++ b/src/native/collector/examples/windows-monitor/main.cpp @@ -5,6 +5,8 @@ // // Usage: hsm_windows_monitor [server_address] [port] [access_key] [seconds] // defaults: https://localhost 44330 demo-key 30 +// Writes NLog-parity log files to ./Logs (override the directory with HSM_LOG_DIR): +// DataCollector_.txt for all levels, DataCollector_error_.txt for errors. #include @@ -23,6 +25,9 @@ int main(int argc, char** argv) const std::string access_key = argc > 3 ? argv[3] : "demo-key"; const int seconds = argc > 4 ? std::atoi(argv[4]) : 30; + const char* log_dir_env = std::getenv("HSM_LOG_DIR"); + const std::string log_dir = (log_dir_env && *log_dir_env) ? log_dir_env : "Logs"; + try { hc::CollectorOptions options; @@ -39,6 +44,11 @@ int main(int argc, char** argv) std::cerr << "[hsm] (" << static_cast(level) << ") " << message << '\n'; }); + // Built-in async file logger (NLog parity) — the feature under test. Writes + // /DataCollector_.txt (+ _error_ for errors), independent of the stderr + // callback above; both sinks receive every message. Enable before Start. + collector.EnableFileLogging(log_dir, hc::LogLevel::Info); + // Real server transport (#1165) + the Windows live readers (#1164). Install both before Start. collector.UseHttpTransport(); collector.InstallWindowsMetricSources(); @@ -48,7 +58,8 @@ int main(int argc, char** argv) collector.AddAllComputerSensors(); collector.AddAllModuleSensors("1.0.0.0"); - std::cout << "Monitoring Windows -> " << server << ':' << port << " for " << seconds << "s...\n"; + std::cout << "Monitoring Windows -> " << server << ':' << port << " for " << seconds + << "s... (log files: " << log_dir << ")\n"; collector.Start(); std::this_thread::sleep_for(std::chrono::seconds(seconds)); collector.Stop(); From 7d6cb903c6785444d6302337ef57616dcc83b4df Mon Sep 17 00:00:00 2001 From: Andrei Date: Fri, 3 Jul 2026 16:56:18 +0200 Subject: [PATCH 2/2] fix(native-examples): silence MSVC C4996 for getenv in windows-monitor MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The HSM_LOG_DIR std::getenv lookup tripped C4996 (getenv deprecation) under the http-transport lane's /WX, failing the Windows build. Define _CRT_SECURE_NO_WARNINGS before the CRT headers — the lookup is a read-only env read. Co-Authored-By: Claude Opus 4.8 --- src/native/collector/examples/windows-monitor/main.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/native/collector/examples/windows-monitor/main.cpp b/src/native/collector/examples/windows-monitor/main.cpp index ac3ed8d7d..74301ec81 100644 --- a/src/native/collector/examples/windows-monitor/main.cpp +++ b/src/native/collector/examples/windows-monitor/main.cpp @@ -8,6 +8,10 @@ // Writes NLog-parity log files to ./Logs (override the directory with HSM_LOG_DIR): // DataCollector_.txt for all levels, DataCollector_error_.txt for errors. +// std::getenv (the HSM_LOG_DIR lookup below) is a read-only env read; silence MSVC's C4996 +// deprecation (must precede the CRT headers). +#define _CRT_SECURE_NO_WARNINGS + #include #include