From f5ab6fb5e8be7b73e6003d4145081d5e0c0ce287 Mon Sep 17 00:00:00 2001 From: Jack <66967891+ASpoonPlaysGames@users.noreply.github.com> Date: Wed, 27 Dec 2023 00:32:01 +0000 Subject: Folder restructuring from primedev (#624) Copies of over the primedev folder structure for easier cherry-picking of further changes Co-authored-by: F1F7Y --- NorthstarDLL/logging/logging.h | 136 ----------------------------------------- 1 file changed, 136 deletions(-) delete mode 100644 NorthstarDLL/logging/logging.h (limited to 'NorthstarDLL/logging/logging.h') diff --git a/NorthstarDLL/logging/logging.h b/NorthstarDLL/logging/logging.h deleted file mode 100644 index 5056af27..00000000 --- a/NorthstarDLL/logging/logging.h +++ /dev/null @@ -1,136 +0,0 @@ -#pragma once -#include "spdlog/sinks/base_sink.h" -#include "spdlog/logger.h" -#include "squirrel/squirrel.h" -#include "core/math/color.h" - -void CreateLogFiles(); -void InitialiseLogging(); -void InitialiseConsole(); -void StartupLog(); - -class ColoredLogger; - -struct custom_log_msg : spdlog::details::log_msg -{ -public: - custom_log_msg(ColoredLogger* origin, spdlog::details::log_msg msg) : origin(origin), spdlog::details::log_msg(msg) {} - - ColoredLogger* origin; -}; - -class CustomSink : public spdlog::sinks::base_sink -{ -public: - void custom_log(const custom_log_msg& msg); - virtual void custom_sink_it_(const custom_log_msg& msg) - { - throw std::runtime_error("Pure virtual call to CustomSink::custom_sink_it_"); - } -}; - -class ColoredLogger : public spdlog::logger -{ -public: - std::string ANSIColor; - SourceColor SRCColor; - - std::vector> custom_sinks_; - - ColoredLogger(std::string name, Color color, bool first = false) : spdlog::logger(*spdlog::default_logger()) - { - name_ = std::move(name); - if (!first) - { - custom_sinks_ = dynamic_pointer_cast(spdlog::default_logger())->custom_sinks_; - } - - ANSIColor = color.ToANSIColor(); - SRCColor = color.ToSourceColor(); - } - - void sink_it_(const spdlog::details::log_msg& msg) - { - custom_log_msg custom_msg {this, msg}; - - // Ugh - for (auto& sink : sinks_) - { - SPDLOG_TRY - { - sink->log(custom_msg); - } - SPDLOG_LOGGER_CATCH() - } - - for (auto& sink : custom_sinks_) - { - SPDLOG_TRY - { - sink->custom_log(custom_msg); - } - SPDLOG_LOGGER_CATCH() - } - - if (should_flush_(custom_msg)) - { - flush_(); - } - } -}; - -namespace NS::log -{ - // Squirrel - extern std::shared_ptr SCRIPT_UI; - extern std::shared_ptr SCRIPT_CL; - extern std::shared_ptr SCRIPT_SV; - - // Native code - extern std::shared_ptr NATIVE_UI; - extern std::shared_ptr NATIVE_CL; - extern std::shared_ptr NATIVE_SV; - extern std::shared_ptr NATIVE_EN; - - // File system - extern std::shared_ptr fs; - // RPak - extern std::shared_ptr rpak; - // Echo - extern std::shared_ptr echo; - - extern std::shared_ptr NORTHSTAR; - - extern std::shared_ptr PLUGINSYS; - - void FlushLoggers(); -}; // namespace NS::log - -void RegisterCustomSink(std::shared_ptr sink); -void RegisterLogger(std::shared_ptr logger); - -inline bool g_bSpdLog_UseAnsiColor = true; - -// Could maybe use some different names here, idk -static const char* level_names[] {"trac", "dbug", "info", "warn", "errr", "crit", "off"}; - -// spdlog logger, for cool colour things -class ExternalConsoleSink : public CustomSink -{ -private: - std::map m_LogColours = { - {spdlog::level::trace, NS::Colors::TRACE.ToANSIColor()}, - {spdlog::level::debug, NS::Colors::DEBUG.ToANSIColor()}, - {spdlog::level::info, NS::Colors::INFO.ToANSIColor()}, - {spdlog::level::warn, NS::Colors::WARN.ToANSIColor()}, - {spdlog::level::err, NS::Colors::ERR.ToANSIColor()}, - {spdlog::level::critical, NS::Colors::CRIT.ToANSIColor()}, - {spdlog::level::off, NS::Colors::OFF.ToANSIColor()}}; - - std::string default_color = "\033[39;49m"; - -protected: - void sink_it_(const spdlog::details::log_msg& msg) override; - void custom_sink_it_(const custom_log_msg& msg); - void flush_() override; -}; -- cgit v1.2.3