Skip to content

Commit

Permalink
Also use during COM init
Browse files Browse the repository at this point in the history
  • Loading branch information
JohnMcPMS committed Nov 14, 2024
1 parent 2306df7 commit ec2f3f7
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
8 changes: 8 additions & 0 deletions src/AppInstallerCLICore/COMContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "COMContext.h"
#include <AppInstallerFileLogger.h>
#include <winget/TraceLogger.h>
#include <winget/OutputDebugStringLogger.h>

namespace AppInstaller::CLI::Execution
{
Expand Down Expand Up @@ -77,12 +78,19 @@ namespace AppInstaller::CLI::Execution

void COMContext::SetLoggers(std::optional<AppInstaller::Logging::Channel> channel, std::optional<AppInstaller::Logging::Level> level)
{
// Set up debug string logging during initialization
Logging::OutputDebugStringLogger::Add();
Logging::Log().EnableChannel(Logging::Channel::All);
Logging::Log().SetLevel(Logging::Level::Verbose);

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);

Logging::OutputDebugStringLogger::Remove();

#ifndef AICLI_DISABLE_TEST_HOOKS
if (!Settings::User().Get<Settings::Setting::KeepAllLogFiles>())
#endif
Expand Down
22 changes: 18 additions & 4 deletions src/AppInstallerCLICore/Core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -185,23 +185,37 @@ namespace AppInstaller::CLI

void ServerInitialize()
{
#ifndef AICLI_DISABLE_TEST_HOOKS
#ifndef AICLI_DISABLE_TEST_HOOKS
// We have to do this here so the auto minidump config initialization gets caught
Logging::OutputDebugStringLogger::Add();
Logging::Log().EnableChannel(Logging::Channel::All);
Logging::Log().SetLevel(Logging::Level::Verbose);

if (Settings::User().Get<Settings::Setting::EnableSelfInitiatedMinidump>())
{
Debugging::EnableSelfInitiatedMinidump();
}
}

Logging::OutputDebugStringLogger::Remove();
#endif

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

void InProcInitialize()
{
#ifndef AICLI_DISABLE_TEST_HOOKS
#ifndef AICLI_DISABLE_TEST_HOOKS
// We have to do this here so the auto minidump config initialization gets caught
Logging::OutputDebugStringLogger::Add();
Logging::Log().EnableChannel(Logging::Channel::All);
Logging::Log().SetLevel(Logging::Level::Verbose);

if (Settings::User().Get<Settings::Setting::EnableSelfInitiatedMinidump>())
{
Debugging::EnableSelfInitiatedMinidump();
}
}

Logging::OutputDebugStringLogger::Remove();
#endif

// Explicitly set default channel and level before user settings from PackageManagerSettings
Expand Down

0 comments on commit ec2f3f7

Please sign in to comment.