From 396dcb04658eef86ff00fffca968950c3f6c4d95 Mon Sep 17 00:00:00 2001 From: David Markowitz <39972741+EmosewaMC@users.noreply.github.com> Date: Sat, 25 Oct 2025 12:53:49 -0700 Subject: [PATCH] feat: add logger feature to log on function entry and exit (#1924) * feat: add logger feature to log on function entry and exit * i didnt save the file --- dCommon/Logger.cpp | 14 ++++++++++++++ dCommon/Logger.h | 13 +++++++++++++ dGame/dBehaviors/AndBehavior.cpp | 2 ++ dGame/dBehaviors/Behavior.h | 2 ++ 4 files changed, 31 insertions(+) diff --git a/dCommon/Logger.cpp b/dCommon/Logger.cpp index 1888f1eb..0f31f541 100644 --- a/dCommon/Logger.cpp +++ b/dCommon/Logger.cpp @@ -96,3 +96,17 @@ bool Logger::GetLogToConsole() const { } return toReturn; } + +FuncEntry::FuncEntry(const char* funcName, const char* fileName, const uint32_t line) { + m_FuncName = funcName; + if (!m_FuncName) m_FuncName = "Unknown"; + m_Line = line; + m_FileName = fileName; + LOG("--> %s::%s:%i", m_FileName, m_FuncName, m_Line); +} + +FuncEntry::~FuncEntry() { + if (!m_FuncName || !m_FileName) return; + + LOG("<-- %s::%s:%i", m_FileName, m_FuncName, m_Line); +} diff --git a/dCommon/Logger.h b/dCommon/Logger.h index 3a1771e6..e7785a13 100644 --- a/dCommon/Logger.h +++ b/dCommon/Logger.h @@ -32,6 +32,19 @@ constexpr const char* GetFileNameFromAbsolutePath(const char* path) { #define LOG(message, ...) do { auto str_ = FILENAME_AND_LINE; Game::logger->Log(str_, message, ##__VA_ARGS__); } while(0) #define LOG_DEBUG(message, ...) do { auto str_ = FILENAME_AND_LINE; Game::logger->LogDebug(str_, message, ##__VA_ARGS__); } while(0) +// Place this right at the start of a function. Will log a message when called and then once you leave the function. +#define LOG_ENTRY auto str_ = GetFileNameFromAbsolutePath(__FILE__); FuncEntry funcEntry_(__FUNCTION__, str_, __LINE__) + +class FuncEntry { +public: + FuncEntry(const char* funcName, const char* fileName, const uint32_t line); + ~FuncEntry(); +private: + const char* m_FuncName = nullptr; + const char* m_FileName = nullptr; + uint32_t m_Line = 0; +}; + // Writer class for writing data to files. class Writer { public: diff --git a/dGame/dBehaviors/AndBehavior.cpp b/dGame/dBehaviors/AndBehavior.cpp index ad986e37..c9d6e06e 100644 --- a/dGame/dBehaviors/AndBehavior.cpp +++ b/dGame/dBehaviors/AndBehavior.cpp @@ -10,7 +10,9 @@ void AndBehavior::Handle(BehaviorContext* context, RakNet::BitStream& bitStream, } void AndBehavior::Calculate(BehaviorContext* context, RakNet::BitStream& bitStream, const BehaviorBranchContext branch) { + LOG_ENTRY; for (auto* behavior : this->m_behaviors) { + LOG("%i calculating %i", m_behaviorId, behavior->GetBehaviorID()); behavior->Calculate(context, bitStream, branch); } } diff --git a/dGame/dBehaviors/Behavior.h b/dGame/dBehaviors/Behavior.h index f9867ffe..49d664c7 100644 --- a/dGame/dBehaviors/Behavior.h +++ b/dGame/dBehaviors/Behavior.h @@ -95,4 +95,6 @@ public: Behavior& operator=(const Behavior& other) = default; Behavior& operator=(Behavior&& other) = default; + + uint32_t GetBehaviorID() const { return m_behaviorId; } };