2017-01-20 14:36:52 +01:00
|
|
|
#pragma once
|
|
|
|
|
2017-01-19 22:23:59 +01:00
|
|
|
namespace Components
|
|
|
|
{
|
|
|
|
class Logger : public Component
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
Logger();
|
|
|
|
~Logger();
|
2022-06-12 23:07:53 +02:00
|
|
|
|
2017-01-19 22:23:59 +01:00
|
|
|
static bool IsConsoleReady();
|
|
|
|
|
2022-07-22 11:27:38 +02:00
|
|
|
static void Print_Stub(int channel, const char* message, ...);
|
2017-01-19 22:23:59 +01:00
|
|
|
|
2022-12-28 13:37:03 +01:00
|
|
|
static void PipeOutput(void(*callback)(const std::string&));
|
2017-01-19 22:23:59 +01:00
|
|
|
|
2022-12-28 11:03:14 +01:00
|
|
|
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);
|
2022-06-12 23:07:53 +02:00
|
|
|
|
2022-12-28 11:03:14 +01:00
|
|
|
static void Print(const std::string_view& fmt)
|
2022-06-12 23:07:53 +02:00
|
|
|
{
|
|
|
|
PrintInternal(Game::CON_CHANNEL_DONT_FILTER, fmt, std::make_format_args(0));
|
|
|
|
}
|
|
|
|
|
2022-12-28 11:03:14 +01:00
|
|
|
static void Print(Game::conChannel_t channel, const std::string_view& fmt)
|
2022-06-12 23:07:53 +02:00
|
|
|
{
|
|
|
|
PrintInternal(channel, fmt, std::make_format_args(0));
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename... Args>
|
2022-12-28 11:03:14 +01:00
|
|
|
static void Print(const std::string_view& fmt, Args&&... args)
|
2022-06-12 23:07:53 +02:00
|
|
|
{
|
2022-11-25 18:33:53 +00:00
|
|
|
(Utils::String::SanitizeFormatArgs(args), ...);
|
2022-06-12 23:07:53 +02:00
|
|
|
PrintInternal(Game::CON_CHANNEL_DONT_FILTER, fmt, std::make_format_args(args...));
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename... Args>
|
2022-12-28 11:03:14 +01:00
|
|
|
static void Print(Game::conChannel_t channel, const std::string_view& fmt, Args&&... args)
|
2022-06-12 23:07:53 +02:00
|
|
|
{
|
2022-11-25 18:33:53 +00:00
|
|
|
(Utils::String::SanitizeFormatArgs(args), ...);
|
2022-06-12 23:07:53 +02:00
|
|
|
PrintInternal(channel, fmt, std::make_format_args(args...));
|
|
|
|
}
|
|
|
|
|
2022-12-28 11:03:14 +01:00
|
|
|
static void Error(Game::errorParm_t error, const std::string_view& fmt)
|
2022-06-12 23:07:53 +02:00
|
|
|
{
|
|
|
|
ErrorInternal(error, fmt, std::make_format_args(0));
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename... Args>
|
2022-12-28 11:03:14 +01:00
|
|
|
static void Error(Game::errorParm_t error, const std::string_view& fmt, Args&&... args)
|
2022-06-12 23:07:53 +02:00
|
|
|
{
|
2022-11-25 18:33:53 +00:00
|
|
|
(Utils::String::SanitizeFormatArgs(args), ...);
|
2022-06-12 23:07:53 +02:00
|
|
|
ErrorInternal(error, fmt, std::make_format_args(args...));
|
|
|
|
}
|
|
|
|
|
2022-12-28 11:03:14 +01:00
|
|
|
static void Warning(Game::conChannel_t channel, const std::string_view& fmt)
|
2022-06-12 23:07:53 +02:00
|
|
|
{
|
|
|
|
WarningInternal(channel, fmt, std::make_format_args(0));
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename... Args>
|
2022-12-28 11:03:14 +01:00
|
|
|
static void Warning(Game::conChannel_t channel, const std::string_view& fmt, Args&&... args)
|
2022-06-12 23:07:53 +02:00
|
|
|
{
|
2022-11-25 18:33:53 +00:00
|
|
|
(Utils::String::SanitizeFormatArgs(args), ...);
|
2022-06-12 23:07:53 +02:00
|
|
|
WarningInternal(channel, fmt, std::make_format_args(args...));
|
|
|
|
}
|
|
|
|
|
2022-12-28 11:03:14 +01:00
|
|
|
static void PrintError(Game::conChannel_t channel, const std::string_view& fmt)
|
2022-06-12 23:07:53 +02:00
|
|
|
{
|
|
|
|
PrintErrorInternal(channel, fmt, std::make_format_args(0));
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename... Args>
|
2022-12-28 11:03:14 +01:00
|
|
|
static void PrintError(Game::conChannel_t channel, const std::string_view& fmt, Args&&... args)
|
2022-06-12 23:07:53 +02:00
|
|
|
{
|
2022-11-25 18:33:53 +00:00
|
|
|
(Utils::String::SanitizeFormatArgs(args), ...);
|
2022-06-12 23:07:53 +02:00
|
|
|
PrintErrorInternal(channel, fmt, std::make_format_args(args...));
|
|
|
|
}
|
|
|
|
|
2022-12-28 11:03:14 +01:00
|
|
|
struct FormatWithLocation
|
2022-06-12 23:07:53 +02:00
|
|
|
{
|
2022-12-28 11:03:14 +01:00
|
|
|
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))
|
2022-06-22 10:58:51 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
};
|
2022-06-12 23:07:53 +02:00
|
|
|
|
|
|
|
template <typename... Args>
|
2022-12-28 11:03:14 +01:00
|
|
|
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
|
|
|
|
}
|
2022-06-12 23:07:53 +02:00
|
|
|
|
2017-01-19 22:23:59 +01:00
|
|
|
private:
|
|
|
|
static std::mutex MessageMutex;
|
|
|
|
static std::vector<std::string> MessageQueue;
|
|
|
|
static std::vector<Network::Address> LoggingAddresses[2];
|
2022-11-17 23:06:47 +00:00
|
|
|
|
2022-12-28 13:37:03 +01:00
|
|
|
static void(*PipeCallback)(const std::string&);
|
2017-01-19 22:23:59 +01:00
|
|
|
|
2022-07-04 21:09:26 +02:00
|
|
|
static void MessagePrint(int channel, const std::string& msg);
|
2022-11-17 23:06:47 +00:00
|
|
|
|
2017-01-19 22:23:59 +01:00
|
|
|
static void Frame();
|
2022-11-17 23:06:47 +00:00
|
|
|
|
2022-07-22 11:27:38 +02:00
|
|
|
static void G_LogPrintf_Hk(const char* fmt, ...);
|
|
|
|
static void PrintMessage_Stub();
|
2017-01-19 22:23:59 +01:00
|
|
|
static void PrintMessagePipe(const char* data);
|
2018-12-17 14:29:18 +01:00
|
|
|
static void EnqueueMessage(const std::string& message);
|
2017-01-19 22:23:59 +01:00
|
|
|
|
2022-07-22 11:27:38 +02:00
|
|
|
static void BuildOSPath_Stub();
|
2017-02-25 01:17:11 +01:00
|
|
|
static void RedirectOSPath(const char* file, char* folder);
|
|
|
|
|
2017-01-19 22:23:59 +01:00
|
|
|
static void NetworkLog(const char* data, bool gLog);
|
2022-06-16 16:15:26 +02:00
|
|
|
|
|
|
|
static void AddServerCommands();
|
2017-01-19 22:23:59 +01:00
|
|
|
};
|
|
|
|
}
|