mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-04 18:26:39 +02:00
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:
55
src/common/logger/call_tracer.cpp
Normal file
55
src/common/logger/call_tracer.cpp
Normal 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());
|
||||
}
|
||||
15
src/common/logger/call_tracer.h
Normal file
15
src/common/logger/call_tracer.h
Normal 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();
|
||||
};
|
||||
@@ -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">
|
||||
|
||||
@@ -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" />
|
||||
|
||||
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user