[Logger]: Refactor

This commit is contained in:
Diavolo 2022-12-28 11:03:14 +01:00
parent 6b212ebe4c
commit 4d1baa17be
No known key found for this signature in database
GPG Key ID: FA77F074E98D98A5
4 changed files with 46 additions and 35 deletions

View File

@ -58,7 +58,7 @@ namespace Components
} }
} }
void Logger::DebugInternal(std::string_view fmt, std::format_args&& args, [[maybe_unused]] const std::source_location& loc) void Logger::DebugInternal(const std::string_view& fmt, std::format_args&& args, [[maybe_unused]] const std::source_location& loc)
{ {
#ifdef LOGGER_TRACE #ifdef LOGGER_TRACE
const auto msg = std::vformat(fmt, args); const auto msg = std::vformat(fmt, args);
@ -71,14 +71,14 @@ namespace Components
MessagePrint(Game::CON_CHANNEL_DONT_FILTER, out); MessagePrint(Game::CON_CHANNEL_DONT_FILTER, out);
} }
void Logger::PrintInternal(Game::conChannel_t channel, std::string_view fmt, std::format_args&& args) void Logger::PrintInternal(Game::conChannel_t channel, const std::string_view& fmt, std::format_args&& args)
{ {
const auto msg = std::vformat(fmt, args); const auto msg = std::vformat(fmt, args);
MessagePrint(channel, msg); MessagePrint(channel, msg);
} }
void Logger::ErrorInternal(const Game::errorParm_t error, const std::string_view fmt, std::format_args&& args) void Logger::ErrorInternal(const Game::errorParm_t error, const std::string_view& fmt, std::format_args&& args)
{ {
#ifdef _DEBUG #ifdef _DEBUG
if (IsDebuggerPresent()) __debugbreak(); if (IsDebuggerPresent()) __debugbreak();
@ -88,7 +88,7 @@ namespace Components
Game::Com_Error(error, "%s", msg.data()); Game::Com_Error(error, "%s", msg.data());
} }
void Logger::PrintErrorInternal(Game::conChannel_t channel, std::string_view fmt, std::format_args&& args) void Logger::PrintErrorInternal(Game::conChannel_t channel, const std::string_view& fmt, std::format_args&& args)
{ {
const auto msg = "^1Error: " + std::vformat(fmt, args); const auto msg = "^1Error: " + std::vformat(fmt, args);
@ -101,7 +101,7 @@ namespace Components
} }
} }
void Logger::WarningInternal(Game::conChannel_t channel, std::string_view fmt, std::format_args&& args) void Logger::WarningInternal(Game::conChannel_t channel, const std::string_view& fmt, std::format_args&& args)
{ {
const auto msg = "^3" + std::vformat(fmt, args); const auto msg = "^3" + std::vformat(fmt, args);

View File

@ -14,87 +14,98 @@ namespace Components
static void PipeOutput(const std::function<void(const std::string&)>& callback); static void PipeOutput(const std::function<void(const std::string&)>& callback);
static void PrintInternal(Game::conChannel_t channel, std::string_view fmt, std::format_args&& args); static void PrintInternal(Game::conChannel_t channel, const std::string_view& fmt, std::format_args&& args);
static void ErrorInternal(Game::errorParm_t error, std::string_view fmt, std::format_args&& args); static void ErrorInternal(Game::errorParm_t error, const std::string_view& fmt, std::format_args&& args);
static void PrintErrorInternal(Game::conChannel_t channel, std::string_view fmt, std::format_args&& args); static void PrintErrorInternal(Game::conChannel_t channel, const std::string_view& fmt, std::format_args&& args);
static void WarningInternal(Game::conChannel_t channel, std::string_view fmt, std::format_args&& args); static void WarningInternal(Game::conChannel_t channel, const std::string_view& fmt, std::format_args&& args);
static void DebugInternal(std::string_view fmt, std::format_args&& args, const std::source_location& loc); static void DebugInternal(const std::string_view& fmt, std::format_args&& args, const std::source_location& loc);
static void Print(std::string_view fmt) static void Print(const std::string_view& fmt)
{ {
PrintInternal(Game::CON_CHANNEL_DONT_FILTER, fmt, std::make_format_args(0)); PrintInternal(Game::CON_CHANNEL_DONT_FILTER, fmt, std::make_format_args(0));
} }
static void Print(Game::conChannel_t channel, std::string_view fmt) static void Print(Game::conChannel_t channel, const std::string_view& fmt)
{ {
PrintInternal(channel, fmt, std::make_format_args(0)); PrintInternal(channel, fmt, std::make_format_args(0));
} }
template <typename... Args> template <typename... Args>
static void Print(std::string_view fmt, Args&&... args) static void Print(const std::string_view& fmt, Args&&... args)
{ {
(Utils::String::SanitizeFormatArgs(args), ...); (Utils::String::SanitizeFormatArgs(args), ...);
PrintInternal(Game::CON_CHANNEL_DONT_FILTER, fmt, std::make_format_args(args...)); PrintInternal(Game::CON_CHANNEL_DONT_FILTER, fmt, std::make_format_args(args...));
} }
template <typename... Args> template <typename... Args>
static void Print(Game::conChannel_t channel, std::string_view fmt, Args&&... args) static void Print(Game::conChannel_t channel, const std::string_view& fmt, Args&&... args)
{ {
(Utils::String::SanitizeFormatArgs(args), ...); (Utils::String::SanitizeFormatArgs(args), ...);
PrintInternal(channel, fmt, std::make_format_args(args...)); PrintInternal(channel, fmt, std::make_format_args(args...));
} }
static void Error(Game::errorParm_t error, std::string_view fmt) static void Error(Game::errorParm_t error, const std::string_view& fmt)
{ {
ErrorInternal(error, fmt, std::make_format_args(0)); ErrorInternal(error, fmt, std::make_format_args(0));
} }
template <typename... Args> template <typename... Args>
static void Error(Game::errorParm_t error, std::string_view fmt, Args&&... args) static void Error(Game::errorParm_t error, const std::string_view& fmt, Args&&... args)
{ {
(Utils::String::SanitizeFormatArgs(args), ...); (Utils::String::SanitizeFormatArgs(args), ...);
ErrorInternal(error, fmt, std::make_format_args(args...)); ErrorInternal(error, fmt, std::make_format_args(args...));
} }
static void Warning(Game::conChannel_t channel, std::string_view fmt) static void Warning(Game::conChannel_t channel, const std::string_view& fmt)
{ {
WarningInternal(channel, fmt, std::make_format_args(0)); WarningInternal(channel, fmt, std::make_format_args(0));
} }
template <typename... Args> template <typename... Args>
static void Warning(Game::conChannel_t channel, std::string_view fmt, Args&&... args) static void Warning(Game::conChannel_t channel, const std::string_view& fmt, Args&&... args)
{ {
(Utils::String::SanitizeFormatArgs(args), ...); (Utils::String::SanitizeFormatArgs(args), ...);
WarningInternal(channel, fmt, std::make_format_args(args...)); WarningInternal(channel, fmt, std::make_format_args(args...));
} }
static void PrintError(Game::conChannel_t channel, std::string_view fmt) static void PrintError(Game::conChannel_t channel, const std::string_view& fmt)
{ {
PrintErrorInternal(channel, fmt, std::make_format_args(0)); PrintErrorInternal(channel, fmt, std::make_format_args(0));
} }
template <typename... Args> template <typename... Args>
static void PrintError(Game::conChannel_t channel, std::string_view fmt, Args&&... args) static void PrintError(Game::conChannel_t channel, const std::string_view& fmt, Args&&... args)
{ {
(Utils::String::SanitizeFormatArgs(args), ...); (Utils::String::SanitizeFormatArgs(args), ...);
PrintErrorInternal(channel, fmt, std::make_format_args(args...)); PrintErrorInternal(channel, fmt, std::make_format_args(args...));
} }
template <typename... Args> struct FormatWithLocation
class Debug
{ {
public: std::string_view format;
Debug([[maybe_unused]] std::string_view fmt, [[maybe_unused]] const Args&... args, [[maybe_unused]] const std::source_location& loc = std::source_location::current()) std::source_location location;
FormatWithLocation(const std::string_view& fmt, std::source_location loc = std::source_location::current())
: format(fmt)
, location(std::move(loc))
{
}
FormatWithLocation(const char* fmt, std::source_location loc = std::source_location::current())
: format(fmt)
, location(std::move(loc))
{ {
#ifdef _DEBUG
(Utils::String::SanitizeFormatArgs(args), ...);
DebugInternal(fmt, std::make_format_args(args...), loc);
#endif
} }
}; };
template <typename... Args> template <typename... Args>
Debug(std::string_view fmt, const Args&... args) -> Debug<Args...>; static void Debug([[maybe_unused]] const FormatWithLocation& f, [[maybe_unused]] const Args&... args)
{
#ifdef _DEBUG
(Utils::String::SanitizeFormatArgs(args), ...);
DebugInternal(f.format, std::make_format_args(args...), f.location);
#endif
}
private: private:
static std::mutex MessageMutex; static std::mutex MessageMutex;

View File

@ -80,7 +80,6 @@
#include <gsl/gsl> #include <gsl/gsl>
#include <tomcrypt.h> #include <tomcrypt.h>
#include <udis86.h>
#include <zlib.h> #include <zlib.h>
// Enable additional literals // Enable additional literals

View File

@ -1,4 +1,5 @@
#include <STDInclude.hpp> #include <STDInclude.hpp>
#include <udis86.h>
namespace Steam namespace Steam
{ {
@ -6,11 +7,11 @@ namespace Steam
::Utils::Library Proxy::Overlay; ::Utils::Library Proxy::Overlay;
ISteamClient008* Proxy::SteamClient = nullptr; ISteamClient008* Proxy::SteamClient = nullptr;
IClientEngine* Proxy::ClientEngine = nullptr; IClientEngine* Proxy::ClientEngine = nullptr;
Interface Proxy::ClientUser; Interface Proxy::ClientUser;
Interface Proxy::ClientFriends; Interface Proxy::ClientFriends;
Interface Proxy::Placeholder; Interface Proxy::Placeholder;
Proxy::Handle Proxy::SteamPipe = nullptr; Proxy::Handle Proxy::SteamPipe = nullptr;
Proxy::Handle Proxy::SteamUser = nullptr; Proxy::Handle Proxy::SteamUser = nullptr;
@ -237,7 +238,7 @@ namespace Steam
{ {
std::lock_guard<std::recursive_mutex> _(Proxy::CallMutex); std::lock_guard<std::recursive_mutex> _(Proxy::CallMutex);
for(auto i = Proxy::Calls.begin(); i != Proxy::Calls.end(); ++i) for (auto i = Proxy::Calls.begin(); i != Proxy::Calls.end(); ++i)
{ {
if(i->handled) if(i->handled)
{ {