From d0d560405c6d8533a6101d374680642aaeadbfdb Mon Sep 17 00:00:00 2001 From: Lion Kortlepel Date: Thu, 15 Feb 2024 17:17:27 +0100 Subject: [PATCH] add readline, start working on a new console sink --- include/TConsole.h | 24 ++++++++++++++++++++++++ src/main.cpp | 31 ++++++++++++++++++++++++++++++- vcpkg.json | 4 +++- 3 files changed, 57 insertions(+), 2 deletions(-) diff --git a/include/TConsole.h b/include/TConsole.h index 24f3df3..12abb2a 100644 --- a/include/TConsole.h +++ b/include/TConsole.h @@ -11,6 +11,30 @@ #include #include #include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +class TConsole; + +class ConsoleSink : public spdlog::sinks::base_sink { +public: + ConsoleSink(TConsole& console); + +private: + void sink_it_(const spdlog::details::log_msg& msg) override; + void flush_() override; + + TConsole* m_console; +}; class TLuaEngine; diff --git a/src/main.cpp b/src/main.cpp index ff4415b..8ea417c 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -10,6 +10,9 @@ #include #include +#include +#include +#include #include static const std::string sCommandlineArguments = R"( @@ -64,6 +67,31 @@ int main(int argc, char** argv) { std::exit(MainRet); } +static std::shared_ptr default_logger; + +static void setup_logger() { + auto console_sink = std::make_shared(); + console_sink->set_pattern("[%H:%M:%S] [%^%l%$] %v"); + if (Application::Settings.DebugModeEnabled) { + console_sink->set_level(spdlog::level::debug); + } else { + console_sink->set_level(spdlog::level::info); + } + + auto file_sink = std::make_shared("Launcher.log", 1024 * 1024, 3, true); + file_sink->set_level(spdlog::level::trace); + file_sink->set_pattern("[%H:%M:%S.%e] [%t] [%l] %v"); + + default_logger = std::make_shared(spdlog::logger("default", { console_sink, file_sink })); + + default_logger->set_level(spdlog::level::trace); + default_logger->flush_on(spdlog::level::trace); + + spdlog::set_default_logger(default_logger); + + spdlog::debug("Logger initialized"); +} + int BeamMPServerMain(MainArguments Arguments) { setlocale(LC_ALL, "C"); ArgsParser Parser; @@ -92,9 +120,10 @@ int BeamMPServerMain(MainArguments Arguments) { auto MaybeConfigPath = Parser.GetValueOfArgument({ "config" }); if (MaybeConfigPath.has_value()) { ConfigPath = MaybeConfigPath.value(); - beammp_info("Custom config requested via commandline arguments: '" + ConfigPath + "'"); + // beammp_info("Custom config requested via commandline arguments: '" + ConfigPath + "'"); } } + setup_logger(); if (Parser.FoundArgument({ "working-directory" })) { auto MaybeWorkingDirectory = Parser.GetValueOfArgument({ "working-directory" }); if (MaybeWorkingDirectory.has_value()) { diff --git a/vcpkg.json b/vcpkg.json index be8b819..6c92783 100644 --- a/vcpkg.json +++ b/vcpkg.json @@ -17,6 +17,8 @@ "toml11", "zstd", "glm", - "libzip" + "libzip", + "spdlog", + "readline" ] }