[Logger]: Refactor
This commit is contained in:
parent
6b212ebe4c
commit
4d1baa17be
@ -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);
|
||||||
|
|
||||||
|
@ -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;
|
||||||
|
@ -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
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
#include <STDInclude.hpp>
|
#include <STDInclude.hpp>
|
||||||
|
#include <udis86.h>
|
||||||
|
|
||||||
namespace Steam
|
namespace Steam
|
||||||
{
|
{
|
||||||
@ -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)
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user