mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-05 10:46:33 +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());
|
||||
}
|
||||
Reference in New Issue
Block a user