add readline, start working on a new console sink

This commit is contained in:
Lion Kortlepel 2024-02-15 17:17:27 +01:00
parent 98c69561b5
commit d0d560405c
No known key found for this signature in database
GPG Key ID: 4322FF2B4C71259B
3 changed files with 57 additions and 2 deletions

View File

@ -11,6 +11,30 @@
#include <tuple> #include <tuple>
#include <unordered_map> #include <unordered_map>
#include <vector> #include <vector>
#include <boost/container/deque.hpp>
#include <boost/thread/scoped_thread.hpp>
#include <boost/thread/synchronized_value.hpp>
#include <memory>
#include <optional>
#include <span>
#include <spdlog/details/null_mutex.h>
#include <spdlog/sinks/base_sink.h>
#include <spdlog/sinks/sink.h>
#include <string>
#include <string_view>
class TConsole;
class ConsoleSink : public spdlog::sinks::base_sink<spdlog::details::null_mutex> {
public:
ConsoleSink(TConsole& console);
private:
void sink_it_(const spdlog::details::log_msg& msg) override;
void flush_() override;
TConsole* m_console;
};
class TLuaEngine; class TLuaEngine;

View File

@ -10,6 +10,9 @@
#include <cstdlib> #include <cstdlib>
#include <iostream> #include <iostream>
#include <spdlog/sinks/rotating_file_sink.h>
#include <spdlog/sinks/stdout_color_sinks.h>
#include <spdlog/spdlog.h>
#include <thread> #include <thread>
static const std::string sCommandlineArguments = R"( static const std::string sCommandlineArguments = R"(
@ -64,6 +67,31 @@ int main(int argc, char** argv) {
std::exit(MainRet); std::exit(MainRet);
} }
static std::shared_ptr<spdlog::logger> default_logger;
static void setup_logger() {
auto console_sink = std::make_shared<spdlog::sinks::stdout_color_sink_mt>();
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<spdlog::sinks::rotating_file_sink_mt>("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>(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) { int BeamMPServerMain(MainArguments Arguments) {
setlocale(LC_ALL, "C"); setlocale(LC_ALL, "C");
ArgsParser Parser; ArgsParser Parser;
@ -92,9 +120,10 @@ int BeamMPServerMain(MainArguments Arguments) {
auto MaybeConfigPath = Parser.GetValueOfArgument({ "config" }); auto MaybeConfigPath = Parser.GetValueOfArgument({ "config" });
if (MaybeConfigPath.has_value()) { if (MaybeConfigPath.has_value()) {
ConfigPath = MaybeConfigPath.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" })) { if (Parser.FoundArgument({ "working-directory" })) {
auto MaybeWorkingDirectory = Parser.GetValueOfArgument({ "working-directory" }); auto MaybeWorkingDirectory = Parser.GetValueOfArgument({ "working-directory" });
if (MaybeWorkingDirectory.has_value()) { if (MaybeWorkingDirectory.has_value()) {

View File

@ -17,6 +17,8 @@
"toml11", "toml11",
"zstd", "zstd",
"glm", "glm",
"libzip" "libzip",
"spdlog",
"readline"
] ]
} }