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

Convert global loggers to Thread local loggers #3

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
Open
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: 6 additions & 0 deletions .github/actions/spelling/expect.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ AICLIC
ajor
amrutha
anonymized
ANSISTRING
APARTMENTTHREADED
apfn
apiset
Expand Down Expand Up @@ -51,9 +52,11 @@ certmgr
certs
Cfg
cgmanifest
cguid
chcp
ci
cinq
Cj
CLIE
cloudapp
CLSID
Expand Down Expand Up @@ -84,6 +87,7 @@ enr
enums
EQU
ERANGE
errcode
errno
etest
execustom
Expand Down Expand Up @@ -259,6 +263,7 @@ srs
Standalone
startswith
streambuf
strlen
strtoull
subdir
subkey
Expand All @@ -272,6 +277,7 @@ temppath
testexampleinstaller
thiscouldbeapc
threehundred
Tlg
tombstoned
transitioning
UCase
Expand Down
21 changes: 20 additions & 1 deletion src/AppInstallerCLICore/COMContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,23 @@ namespace AppInstaller
m_executionStage = executionStage;
m_comProgressCallback(ReportType::ExecutionPhaseUpdate, 0, 0, ProgressType::None, m_executionStage);
}
}

void COMContext::SetLoggers(std::string telemetryCorelationJson, std::string comCaller)
{
SetThreadGlobalsActive();

Logging::Log().SetLevel(Logging::Level::Verbose);
Logging::AddTraceLogger();

#ifdef _DEBUG
// Log to file for COM API calls only when debugging in visual studio
Logging::AddFileLogger();
Logging::BeginLogFileCleanup();
#endif

Logging::EnableWilFailureTelemetry();
Logging::Telemetry().SetTelemetryCorelationJson(telemetryCorelationJson);
Logging::Telemetry().SetCOMCaller(comCaller);
Logging::Telemetry().LogStartup(true);
}
}
5 changes: 5 additions & 0 deletions src/AppInstallerCLICore/COMContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,17 @@ namespace AppInstaller
//Execution::Context
void SetExecutionStage(CLI::Workflow::ExecutionStage executionPhase, bool);

// Set Progress Callback function
void SetProgressCallbackFunction(ProgressCallBackFunction&& f)
{
m_comProgressCallback = std::move(f);
}

private:

// Set diagnostic and telemetry loggers
void SetLoggers(std::string telemetryCorelationJson, std::string comCaller);

CLI::Workflow::ExecutionStage m_executionStage = CLI::Workflow::ExecutionStage::Initial;
ProgressCallBackFunction m_comProgressCallback;
};
Expand Down
10 changes: 7 additions & 3 deletions src/AppInstallerCLICore/Core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,17 @@ namespace AppInstaller::CLI
{
init_apartment();

Execution::Context context{ std::cout, std::cin };
context.EnableCtrlHandler();

// Enable all logging for this phase; we will update once we have the arguments
context.SetThreadGlobalsActive();

Logging::Log().EnableChannel(Logging::Channel::All);
Logging::Log().SetLevel(Logging::Level::Verbose);
Logging::AddFileLogger();

Logging::AddTraceLogger();
Logging::EnableWilFailureTelemetry();

// Set output to UTF8
Expand All @@ -60,9 +67,6 @@ namespace AppInstaller::CLI
// Initiate the background cleanup of the log file location.
Logging::BeginLogFileCleanup();

Execution::Context context{ std::cout, std::cin };
context.EnableCtrlHandler();

context << Workflow::ReportExecutionStage(Workflow::ExecutionStage::ParseArgs);

// Convert incoming wide char args to UTF8
Expand Down
5 changes: 5 additions & 0 deletions src/AppInstallerCLICore/ExecutionContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -140,4 +140,9 @@ namespace AppInstaller::CLI::Execution

m_executionStage = stage;
}

void Context::SetThreadGlobalsActive()
{
m_threadGlobals.SetForCurrentThread();
}
}
6 changes: 5 additions & 1 deletion src/AppInstallerCLICore/ExecutionContext.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
#pragma once
#include <AppInstallerLogging.h>
#include <ThreadGlobals.h>
#include "ExecutionReporter.h"
#include "ExecutionArgs.h"
#include "ExecutionContextData.h"
Expand Down Expand Up @@ -101,6 +101,9 @@ namespace AppInstaller::CLI::Execution
}

virtual void SetExecutionStage(Workflow::ExecutionStage stage, bool);

// Set Globals for Current Thread
void SetThreadGlobalsActive();

#ifndef AICLI_DISABLE_TEST_HOOKS
// Enable tests to override behavior
Expand All @@ -114,5 +117,6 @@ namespace AppInstaller::CLI::Execution
size_t m_CtrlSignalCount = 0;
ContextFlag m_flags = ContextFlag::None;
Workflow::ExecutionStage m_executionStage = Workflow::ExecutionStage::Initial;
AppInstaller::ThreadLocalStorage::ThreadGlobals m_threadGlobals;
};
}
17 changes: 17 additions & 0 deletions src/AppInstallerCLITests/ActivateThreadGlobals.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#include "pch.h"
#include "Public/ThreadGlobals.h"

namespace AppInstaller::ThreadLocalStorage
{
ThreadGlobals* ThreadGlobals::ActivateThreadGlobals(AppInstaller::ThreadLocalStorage::ThreadGlobals* pThreadGlobals)
{
static AppInstaller::ThreadLocalStorage::ThreadGlobals* t_pThreadGlobals = nullptr;

if (pThreadGlobals)
{
t_pThreadGlobals = pThreadGlobals;
}

return t_pThreadGlobals;
}
}
1 change: 1 addition & 0 deletions src/AppInstallerCLITests/AppInstallerCLITests.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@
<ClInclude Include="TestSource.h" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="ActivateThreadGlobals.cpp" />
<ClCompile Include="ARPChanges.cpp" />
<ClCompile Include="Command.cpp" />
<ClCompile Include="Completion.cpp" />
Expand Down
Loading