Skip to content

Commit c20c717

Browse files
authored
Fix logging channel setting (#5261)
## Issue The user setting to control the logging channels was no longer being respected after a previous change to enable all channels during initialization (and to send the initialization logs to the debug stream). ## Change `EnableChannel` for logging has always been semantically "add the given channel(s) to the list of enabled channels". Every place that we were calling `EnableChannel` was really semantically wanting to set the list of enabled channels rather than add to it. This change creates a new function `SetEnabledChannels` that behaves that way; it simply sets the enabled channel mask to the given value. All callers of `EnableChannel` were changed to use this new function.
1 parent ec46ec3 commit c20c717

File tree

10 files changed

+23
-15
lines changed

10 files changed

+23
-15
lines changed

src/AppInstallerCLICore/COMContext.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,10 +80,10 @@ namespace AppInstaller::CLI::Execution
8080
{
8181
// Set up debug string logging during initialization
8282
Logging::OutputDebugStringLogger::Add();
83-
Logging::Log().EnableChannel(Logging::Channel::All);
83+
Logging::Log().SetEnabledChannels(Logging::Channel::All);
8484
Logging::Log().SetLevel(Logging::Level::Verbose);
8585

86-
Logging::Log().EnableChannel(channel.has_value() ? channel.value() : Settings::User().Get<Settings::Setting::LoggingChannelPreference>());
86+
Logging::Log().SetEnabledChannels(channel.has_value() ? channel.value() : Settings::User().Get<Settings::Setting::LoggingChannelPreference>());
8787
Logging::Log().SetLevel(level.has_value() ? level.value() : Settings::User().Get<Settings::Setting::LoggingLevelPreference>());
8888

8989
// TODO: Log to file for COM API calls only when debugging in visual studio

src/AppInstallerCLICore/Core.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ namespace AppInstaller::CLI
7070
#ifndef AICLI_DISABLE_TEST_HOOKS
7171
// We have to do this here so the auto minidump config initialization gets caught
7272
Logging::OutputDebugStringLogger::Add();
73-
Logging::Log().EnableChannel(Logging::Channel::All);
73+
Logging::Log().SetEnabledChannels(Logging::Channel::All);
7474
Logging::Log().SetLevel(Logging::Level::Verbose);
7575

7676
if (Settings::User().Get<Settings::Setting::EnableSelfInitiatedMinidump>())
@@ -88,10 +88,10 @@ namespace AppInstaller::CLI
8888

8989
// Set up debug string logging during initialization
9090
Logging::OutputDebugStringLogger::Add();
91-
Logging::Log().EnableChannel(Logging::Channel::All);
91+
Logging::Log().SetEnabledChannels(Logging::Channel::All);
9292
Logging::Log().SetLevel(Logging::Level::Verbose);
9393

94-
Logging::Log().EnableChannel(Settings::User().Get<Settings::Setting::LoggingChannelPreference>());
94+
Logging::Log().SetEnabledChannels(Settings::User().Get<Settings::Setting::LoggingChannelPreference>());
9595
Logging::Log().SetLevel(Settings::User().Get<Settings::Setting::LoggingLevelPreference>());
9696
Logging::FileLogger::Add();
9797
Logging::OutputDebugStringLogger::Remove();
@@ -192,7 +192,7 @@ namespace AppInstaller::CLI
192192
#ifndef AICLI_DISABLE_TEST_HOOKS
193193
// We have to do this here so the auto minidump config initialization gets caught
194194
Logging::OutputDebugStringLogger::Add();
195-
Logging::Log().EnableChannel(Logging::Channel::All);
195+
Logging::Log().SetEnabledChannels(Logging::Channel::All);
196196
Logging::Log().SetLevel(Logging::Level::Verbose);
197197

198198
if (Settings::User().Get<Settings::Setting::EnableSelfInitiatedMinidump>())
@@ -211,7 +211,7 @@ namespace AppInstaller::CLI
211211
#ifndef AICLI_DISABLE_TEST_HOOKS
212212
// We have to do this here so the auto minidump config initialization gets caught
213213
Logging::OutputDebugStringLogger::Add();
214-
Logging::Log().EnableChannel(Logging::Channel::All);
214+
Logging::Log().SetEnabledChannels(Logging::Channel::All);
215215
Logging::Log().SetLevel(Logging::Level::Verbose);
216216

217217
if (Settings::User().Get<Settings::Setting::EnableSelfInitiatedMinidump>())

src/AppInstallerCLITests/main.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) Microsoft Corporation.
1+
// Copyright (c) Microsoft Corporation.
22
// Licensed under the MIT License.
33
#define CATCH_CONFIG_RUNNER
44
#include <catch.hpp>
@@ -137,7 +137,7 @@ int main(int argc, char** argv)
137137
// Disable SQL by default, as it generates 10s of MBs of log file and
138138
// increases the full test run time by 60% or more.
139139
// By not creating a log target, it will all be thrown away.
140-
Logging::Log().EnableChannel(Logging::Channel::All);
140+
Logging::Log().SetEnabledChannels(Logging::Channel::All);
141141
if (!keepSQLLogging)
142142
{
143143
Logging::Log().DisableChannel(Logging::Channel::SQL);

src/AppInstallerRepositoryCore/InstallerMetadataCollectionContext.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -981,7 +981,7 @@ namespace AppInstaller::Repository::Metadata
981981
auto threadGlobalsLifetime = threadGlobals.SetForCurrentThread();
982982

983983
Logging::Log().SetLevel(Logging::Level::Info);
984-
Logging::Log().EnableChannel(Logging::Channel::All);
984+
Logging::Log().SetEnabledChannels(Logging::Channel::All);
985985
Logging::EnableWilFailureTelemetry();
986986
Logging::TraceLogger::Add();
987987

src/AppInstallerSharedLib/AppInstallerLogging.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,11 @@ namespace AppInstaller::Logging
124124
WI_SetAllFlags(m_enabledChannels, channel);
125125
}
126126

127+
void DiagnosticLogger::SetEnabledChannels(Channel channel)
128+
{
129+
m_enabledChannels = channel;
130+
}
131+
127132
void DiagnosticLogger::DisableChannel(Channel channel)
128133
{
129134
WI_ClearAllFlags(m_enabledChannels, channel);

src/AppInstallerSharedLib/Public/AppInstallerLogging.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,9 +134,12 @@ namespace AppInstaller::Logging
134134
// Removes all loggers.
135135
void RemoveAllLoggers();
136136

137-
// Enables the given channel.
137+
// Enables the given channel(s), in addition to the currently enabled channels.
138138
void EnableChannel(Channel channel);
139139

140+
// The given channel mask will become the only enabled channels.
141+
void SetEnabledChannels(Channel channel);
142+
140143
// Disables the given channel.
141144
void DisableChannel(Channel channel);
142145

src/Microsoft.Management.Configuration/ConfigurationProcessor.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ namespace winrt::Microsoft::Management::Configuration::implementation
119119
THROW_HR_IF(APPINSTALLER_CLI_ERROR_BLOCKED_BY_POLICY, !::AppInstaller::Settings::GroupPolicies().IsEnabled(::AppInstaller::Settings::TogglePolicy::Policy::Configuration));
120120

121121
AppInstaller::Logging::DiagnosticLogger& logger = m_threadGlobals.GetDiagnosticLogger();
122-
logger.EnableChannel(AppInstaller::Logging::Channel::All);
122+
logger.SetEnabledChannels(AppInstaller::Logging::Channel::All);
123123
logger.SetLevel(AppInstaller::Logging::Level::Verbose);
124124
logger.AddLogger(std::make_unique<ConfigurationProcessorDiagnosticsLogger>(*this));
125125
}

src/Microsoft.Management.Deployment/PackageManagerSettings.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ namespace winrt::Microsoft::Management::Deployment::implementation
5050
success = AppInstaller::Settings::TryInitializeCustomUserSettings(AppInstaller::Utility::ConvertToUTF8(settingsContent));
5151
if (success)
5252
{
53-
AppInstaller::Logging::Log().EnableChannel(AppInstaller::Settings::User().Get<AppInstaller::Settings::Setting::LoggingChannelPreference>());
53+
AppInstaller::Logging::Log().SetEnabledChannels(AppInstaller::Settings::User().Get<AppInstaller::Settings::Setting::LoggingChannelPreference>());
5454
AppInstaller::Logging::Log().SetLevel(AppInstaller::Settings::User().Get<AppInstaller::Settings::Setting::LoggingLevelPreference>());
5555
}
5656
});

src/WinGetUtil/Exports.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ extern "C"
5555
// Intentionally release to leave the local ThreadGlobals.
5656
previous.release();
5757
// Enable all logs for now.
58-
AppInstaller::Logging::Log().EnableChannel(AppInstaller::Logging::Channel::All);
58+
AppInstaller::Logging::Log().SetEnabledChannels(AppInstaller::Logging::Channel::All);
5959
AppInstaller::Logging::Log().SetLevel(AppInstaller::Logging::Level::Verbose);
6060
AppInstaller::Logging::EnableWilFailureTelemetry();
6161
});

src/WindowsPackageManager/ConfigurationStaticFunctions.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ namespace ConfigurationShim
4949
{
5050
auto threadGlobalsRestore = m_threadGlobals.SetForCurrentThread();
5151
auto& diagnosticsLogger = m_threadGlobals.GetDiagnosticLogger();
52-
diagnosticsLogger.EnableChannel(AppInstaller::Logging::Channel::All);
52+
diagnosticsLogger.SetEnabledChannels(AppInstaller::Logging::Channel::All);
5353
diagnosticsLogger.SetLevel(AppInstaller::Logging::Level::Verbose);
5454
diagnosticsLogger.AddLogger(std::make_unique<AppInstaller::Logging::FileLogger>("ConfigStatics"sv));
5555

0 commit comments

Comments
 (0)