Commit 596392fc authored by Joe Downing's avatar Joe Downing Committed by Chromium LUCI CQ

Use the value of the logging regkey to enable/disable logging

I noticed today that the file logger in Windows still wrote a file
after I disabled it via the registry.  I tracked the issue down and
it's because the current impl starts the file/event log loggers if
the registry key exists (instead of checking for existence and then
checking the value).

This CL fixes that by only creating the logger instance if the
pertinent reg key exists and has a non-zero value.

Change-Id: I2dabd7c52af831af228fbc2217ced7fd14126ae1
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2582425
Auto-Submit: Joe Downing <joedow@chromium.org>
Commit-Queue: Joe Downing <joedow@chromium.org>
Commit-Queue: Jamie Walch <jamiewalch@chromium.org>
Reviewed-by: default avatarJamie Walch <jamiewalch@chromium.org>
Cr-Commit-Position: refs/heads/master@{#835335}
parent b4c7434f
...@@ -427,15 +427,15 @@ void DaemonProcessWin::ConfigureHostLogging() { ...@@ -427,15 +427,15 @@ void DaemonProcessWin::ConfigureHostLogging() {
if (logging_reg_key.HasValue(kLogToFileRegistryValue)) { if (logging_reg_key.HasValue(kLogToFileRegistryValue)) {
DWORD enabled = 0; DWORD enabled = 0;
result = logging_reg_key.ReadValueDW(kLogToFileRegistryValue, &enabled); result = logging_reg_key.ReadValueDW(kLogToFileRegistryValue, &enabled);
if (result == ERROR_SUCCESS) { if (result != ERROR_SUCCESS) {
::SetLastError(result);
PLOG(ERROR) << "Failed to read HKLM\\" << kLoggingRegistryKeyName << "\\"
<< kLogToFileRegistryValue;
} else if (enabled) {
auto file_logger = HostEventFileLogger::Create(); auto file_logger = HostEventFileLogger::Create();
if (file_logger) { if (file_logger) {
loggers.push_back(std::move(file_logger)); loggers.push_back(std::move(file_logger));
} }
} else {
::SetLastError(result);
PLOG(ERROR) << "Failed to read HKLM\\" << kLoggingRegistryKeyName << "\\"
<< kLogToFileRegistryValue;
} }
} }
...@@ -443,15 +443,15 @@ void DaemonProcessWin::ConfigureHostLogging() { ...@@ -443,15 +443,15 @@ void DaemonProcessWin::ConfigureHostLogging() {
if (logging_reg_key.HasValue(kLogToEventLogRegistryValue)) { if (logging_reg_key.HasValue(kLogToEventLogRegistryValue)) {
DWORD enabled = 0; DWORD enabled = 0;
result = logging_reg_key.ReadValueDW(kLogToEventLogRegistryValue, &enabled); result = logging_reg_key.ReadValueDW(kLogToEventLogRegistryValue, &enabled);
if (result == ERROR_SUCCESS) { if (result != ERROR_SUCCESS) {
::SetLastError(result);
PLOG(ERROR) << "Failed to read HKLM\\" << kLoggingRegistryKeyName << "\\"
<< kLogToEventLogRegistryValue;
} else if (enabled) {
auto event_logger = HostEventWindowsEventLogger::Create(); auto event_logger = HostEventWindowsEventLogger::Create();
if (event_logger) { if (event_logger) {
loggers.push_back(std::move(event_logger)); loggers.push_back(std::move(event_logger));
} }
} else {
::SetLastError(result);
PLOG(ERROR) << "Failed to read HKLM\\" << kLoggingRegistryKeyName << "\\"
<< kLogToEventLogRegistryValue;
} }
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment