Skip to content

Commit cdf7f58

Browse files
committed
logging control via registry
1 parent 15146a2 commit cdf7f58

File tree

3 files changed

+14
-7
lines changed

3 files changed

+14
-7
lines changed

IntelPresentMon/CommonUtilities/reg/Registry.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,10 @@ namespace pmon::util::reg
104104
}
105105
bool Exists() const
106106
{
107+
if (!parent_.key_.IsValid()) {
108+
pmlog_warn(ReportException("Attempting to check validity of value whose key is not open"));
109+
return false;
110+
}
107111
for (auto& v : parent_.key_.EnumValues()) {
108112
if (v.first == valueName_) {
109113
return true;

IntelPresentMon/PresentMonService/LogSetup.cpp

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include "../CommonUtilities/str/String.h"
1818
#include "../CommonUtilities/Exception.h"
1919
#include "CliOptions.h"
20+
#include "Registry.h"
2021

2122
namespace pmon::util::log
2223
{
@@ -63,23 +64,25 @@ namespace logsetup
6364
void ConfigureLogging(bool asApp) noexcept
6465
{
6566
try {
66-
// shortcut for command line
67+
// shortcuts for command line and registry
6768
const auto& opt = clio::Options::Get();
69+
const auto& reg = Reg::Get();
6870
// get the channel
6971
auto pChannel = GetDefaultChannel();
7072
// configure logging based on command line
71-
if (opt.logLevel) {
72-
GlobalPolicy::Get().SetLogLevel(*opt.logLevel);
73+
if (opt.logLevel || reg.logLevel.Exists()) {
74+
GlobalPolicy::Get().SetLogLevel(opt.logLevel ? *opt.logLevel : reg.logLevel);
7375
}
7476
if (!opt.enableStdioLog) {
7577
pChannel->AttachComponent({}, "drv:std");
7678
}
7779
if (!opt.enableDebuggerLog) {
7880
pChannel->AttachComponent({}, "drv:dbg");
7981
}
80-
if (opt.logDir) {
82+
if (opt.logDir || reg.logDir.Exists()) {
83+
const auto dir = opt.logDir ? *opt.logDir : reg.logDir;
8184
const std::chrono::zoned_time now{ std::chrono::current_zone(), std::chrono::system_clock::now() };
82-
auto fullPath = std::format("{0}\\pmsvc-log-{1:%y}{1:%m}{1:%d}-{1:%H}{1:%M}{1:%OS}.txt", *opt.logDir, now);
85+
auto fullPath = std::format("{0}\\pmsvc-log-{1:%y}{1:%m}{1:%d}-{1:%H}{1:%M}{1:%OS}.txt", dir, now);
8386
pChannel->AttachComponent(std::make_shared<BasicFileDriver>( std::make_shared<TextFormatter>(),
8487
std::make_shared<SimpleFileStrategy>(fullPath)), "drv:file");
8588
}

IntelPresentMon/PresentMonService/ServiceMain.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@ int CommonEntry(DWORD argc, LPTSTR* argv, bool asApp)
1919
if (auto e = clio::Options::Init(argc, argv); e && asApp) {
2020
return *e;
2121
}
22-
// configure logging based on CLI arguments
23-
logsetup::ConfigureLogging(asApp);
2422
// configure windows registry access
2523
Reg::SetPrivileged(!asApp);
24+
// configure logging based on CLI arguments and registry settings
25+
logsetup::ConfigureLogging(asApp);
2626

2727
if (asApp) {
2828
auto& svc = ConsoleDebugMockService::Get();

0 commit comments

Comments
 (0)