Merge pull request #678 from diamante0018/refactor/logger

[Logger]: Refactor
This commit is contained in:
Edo 2022-12-28 11:09:55 +01:00 committed by GitHub
commit abaa8eeaef
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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
const auto msg = std::vformat(fmt, args);
@ -71,14 +71,14 @@ namespace Components
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);
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
if (IsDebuggerPresent()) __debugbreak();
@ -88,7 +88,7 @@ namespace Components
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);
@ -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);

View File

@ -14,87 +14,98 @@ namespace Components
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 ErrorInternal(Game::errorParm_t error, 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 WarningInternal(Game::conChannel_t channel, 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 PrintInternal(Game::conChannel_t channel, const 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, const 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(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));
}
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));
}
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), ...);
PrintInternal(Game::CON_CHANNEL_DONT_FILTER, fmt, std::make_format_args(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), ...);
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));
}
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), ...);
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));
}
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), ...);
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));
}
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), ...);
PrintErrorInternal(channel, fmt, std::make_format_args(args...));
}
template <typename... Args>
class Debug
struct FormatWithLocation
{
public:
Debug([[maybe_unused]] std::string_view fmt, [[maybe_unused]] const Args&... args, [[maybe_unused]] const std::source_location& loc = std::source_location::current())
std::string_view format;
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>
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:
static std::mutex MessageMutex;

View File

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

View File

@ -1,4 +1,5 @@
#include <STDInclude.hpp>
#include <udis86.h>
namespace Steam
{
@ -237,7 +238,7 @@ namespace Steam
{
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)
{