Add logging for PowerRename (#14249)

* Add logging for PowerRename

Move call tracer to common/utils/logger
Add logging to both PowerRename dll and PowerRenameUIHost
Add PowerRename to BugReportTool event viewer collection

* Log more errors and exceptions
This commit is contained in:
Stefan Markovic
2021-11-08 13:02:56 +01:00
committed by GitHub
parent c9dca6802e
commit 079a3b49de
16 changed files with 177 additions and 53 deletions

View File

@@ -0,0 +1,55 @@
#include "pch.h"
#include "call_tracer.h"
#include <map>
#include <thread>
namespace
{
// Non-localizable
const std::string entering = " Enter";
const std::string exiting = " Exit";
std::mutex indentLevelMutex;
std::map<std::thread::id, int> indentLevel;
std::string GetIndentation()
{
std::unique_lock lock(indentLevelMutex);
int level = indentLevel[std::this_thread::get_id()];
if (level <= 0)
{
return {};
}
else
{
return std::string(2 * min(level, 64) - 1, ' ') + " - ";
}
}
void Indent()
{
std::unique_lock lock(indentLevelMutex);
indentLevel[std::this_thread::get_id()]++;
}
void Unindent()
{
std::unique_lock lock(indentLevelMutex);
indentLevel[std::this_thread::get_id()]--;
}
}
CallTracer::CallTracer(const char* functionName) :
functionName(functionName)
{
Logger::trace((GetIndentation() + functionName + entering).c_str());
Indent();
}
CallTracer::~CallTracer()
{
Unindent();
Logger::trace((GetIndentation() + functionName + exiting).c_str());
}

View File

@@ -0,0 +1,15 @@
#pragma once
#include <string>
#include "logger.h"
#define _TRACER_ CallTracer callTracer(__FUNCTION__)
class CallTracer
{
std::string functionName;
public:
CallTracer(const char* functionName);
~CallTracer();
};

View File

@@ -31,12 +31,14 @@
</ClCompile>
</ItemDefinitionGroup>
<ItemGroup>
<ClInclude Include="call_tracer.h" />
<ClInclude Include="framework.h" />
<ClInclude Include="logger.h" />
<ClInclude Include="logger_settings.h" />
<ClInclude Include="pch.h" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="call_tracer.cpp" />
<ClCompile Include="logger.cpp" />
<ClCompile Include="logger_settings.cpp" />
<ClCompile Include="pch.cpp">

View File

@@ -27,6 +27,9 @@
<ClInclude Include="logger_settings.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="call_tracer.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="logger.cpp">
@@ -38,6 +41,9 @@
<ClCompile Include="logger_settings.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="call_tracer.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />

View File

@@ -24,6 +24,7 @@ struct LogSettings
inline const static std::string keyboardManagerLoggerName = "keyboard-manager";
inline const static std::wstring keyboardManagerLogPath = L"Logs\\keyboard-manager-log.txt";
inline const static std::string findMyMouseLoggerName = "find-my-mouse";
inline const static std::string powerRenameLoggerName = "powerrename";
inline const static int retention = 30;
std::wstring logLevel;
LogSettings();