From 45d67224d37031e2b70265522b6cd055ca54029f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benjamin=20H=C3=B6glinger-Stelzer?= Date: Fri, 2 Feb 2024 18:40:58 +0100 Subject: [PATCH] Improved logger in watchdog --- Watchdog/App.cpp | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/Watchdog/App.cpp b/Watchdog/App.cpp index d00a6eb..8ff73c2 100644 --- a/Watchdog/App.cpp +++ b/Watchdog/App.cpp @@ -23,6 +23,8 @@ DEFINE_GUID(GUID_DEVCLASS_XBOXCOMPOSITE, // class WatchdogTask : public Poco::Task { + bool _isInteractive; + static DWORD CheckServiceStatus(const std::wstring& serviceName, unsigned long& serviceState) { SC_HANDLE sch = nullptr; @@ -85,14 +87,19 @@ class WatchdogTask : public Poco::Task } public: - explicit WatchdogTask(const std::string& name) + explicit WatchdogTask(const std::string& name, bool isInteractive) : Task(name) { + _isInteractive = isInteractive; } void runTask() override { - spdlog::get("console")->info("Started watchdog background thread"); + const auto logger = _isInteractive + ? spdlog::get("console") + : spdlog::get("eventlog"); + + logger->info("Started watchdog background thread"); do { @@ -167,7 +174,7 @@ class WatchdogTask : public Poco::Task // sleep breaks on app termination while (!sleep(5000)); - spdlog::get("console")->info("Stopping watchdog background thread"); + logger->info("Stopping watchdog background thread"); } }; @@ -207,7 +214,7 @@ int App::main(const std::vector& args) if (is_admin) { Poco::TaskManager tm; - tm.start(new WatchdogTask("HidHideWatchdog")); + tm.start(new WatchdogTask("HidHideWatchdog", this->isInteractive())); waitForTerminationRequest(); tm.cancelAll(); tm.joinAll();