Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initialize logging of global logger for inproc invocations #4490

Merged
merged 2 commits into from
May 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/AppInstallerCLICore/COMContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,10 @@ namespace AppInstaller::CLI::Execution
return m_correlationData;
}

void COMContext::SetLoggers()
void COMContext::SetLoggers(std::optional<AppInstaller::Logging::Channel> channel, std::optional<AppInstaller::Logging::Level> level)
{
Logging::Log().EnableChannel(Settings::User().Get<Settings::Setting::LoggingChannelPreference>());
Logging::Log().SetLevel(Settings::User().Get<Settings::Setting::LoggingLevelPreference>());
Logging::Log().EnableChannel(channel.has_value() ? channel.value() : Settings::User().Get<Settings::Setting::LoggingChannelPreference>());
Logging::Log().SetLevel(level.has_value() ? level.value() : Settings::User().Get<Settings::Setting::LoggingLevelPreference>());

// TODO: Log to file for COM API calls only when debugging in visual studio
Logging::FileLogger::Add(s_comLogFileNamePrefix);
Expand Down
2 changes: 1 addition & 1 deletion src/AppInstallerCLICore/COMContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ namespace AppInstaller::CLI::Execution

// Set Diagnostic and Telemetry loggers, Wil failure callback
// This should be called only once per COM Server instance
static void SetLoggers();
static void SetLoggers(std::optional<AppInstaller::Logging::Channel> channel = std::nullopt, std::optional<AppInstaller::Logging::Level> level = std::nullopt);

// Set COM call context for diagnostic and telemetry loggers
// This should be called for every COMContext object instance
Expand Down
13 changes: 13 additions & 0 deletions src/AppInstallerCLICore/Core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -179,5 +179,18 @@ namespace AppInstaller::CLI
#endif

AppInstaller::CLI::Execution::COMContext::SetLoggers();
}

void InProcInitialize()
{
#ifndef AICLI_DISABLE_TEST_HOOKS
if (Settings::User().Get<Settings::Setting::EnableSelfInitiatedMinidump>())
{
Debugging::EnableSelfInitiatedMinidump();
}
#endif

// Explicitly set default channel and level before user settings from PackageManagerSettings
AppInstaller::CLI::Execution::COMContext::SetLoggers(AppInstaller::Logging::Channel::Defaults, AppInstaller::Logging::Level::Info);
}
}
3 changes: 3 additions & 0 deletions src/AppInstallerCLICore/Public/AppInstallerCLICore.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,7 @@ namespace AppInstaller::CLI

// Initializes the Windows Package Manager COM server.
void ServerInitialize();

// Initializations for InProc invocation.
void InProcInitialize();
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@ namespace winrt::Microsoft::Management::Deployment::implementation
[&]()
{
success = AppInstaller::Settings::TryInitializeCustomUserSettings(AppInstaller::Utility::ConvertToUTF8(settingsContent));
if (success)
{
AppInstaller::Logging::Log().EnableChannel(AppInstaller::Settings::User().Get<AppInstaller::Settings::Setting::LoggingChannelPreference>());
AppInstaller::Logging::Log().SetLevel(AppInstaller::Settings::User().Get<AppInstaller::Settings::Setting::LoggingLevelPreference>());
}
});
return success;
}
Expand Down
1 change: 1 addition & 0 deletions src/WindowsPackageManager/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ extern "C"
WINDOWS_PACKAGE_MANAGER_API WindowsPackageManagerInProcModuleInitialize() try
{
::Microsoft::WRL::Module<::Microsoft::WRL::ModuleType::InProc>::Create();
AppInstaller::CLI::InProcInitialize();
return S_OK;
}
CATCH_RETURN();
Expand Down
Loading