Skip to content

Commit

Permalink
Improved logger in watchdog
Browse files Browse the repository at this point in the history
  • Loading branch information
nefarius committed Feb 2, 2024
1 parent 8ed8b66 commit 45d6722
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions Watchdog/App.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
{
Expand Down Expand Up @@ -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");
}
};

Expand Down Expand Up @@ -207,7 +214,7 @@ int App::main(const std::vector<std::string>& args)
if (is_admin)
{
Poco::TaskManager tm;
tm.start(new WatchdogTask("HidHideWatchdog"));
tm.start(new WatchdogTask("HidHideWatchdog", this->isInteractive()));
waitForTerminationRequest();
tm.cancelAll();
tm.joinAll();
Expand Down

0 comments on commit 45d6722

Please sign in to comment.