From 4687e55186f4df1cd8e9a1c2f3fd44f13942b1b6 Mon Sep 17 00:00:00 2001 From: Lachezar Tsochev Date: Fri, 13 Mar 2026 16:05:32 +0200 Subject: [PATCH] feat(core): configure log file path from core config --- src/core/coreconfig.cpp | 1 + src/core/coreconfig.h | 1 + src/core/log.cpp | 5 +++-- src/core/log.h | 3 ++- src/mm_plugin.cpp | 3 +++ 5 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/core/coreconfig.cpp b/src/core/coreconfig.cpp index 6a279b2cf..11eb7e603 100644 --- a/src/core/coreconfig.cpp +++ b/src/core/coreconfig.cpp @@ -62,6 +62,7 @@ bool CCoreConfig::Init(char* conf_error, int conf_error_size) UnlockConVars = m_json.value("UnlockConVars", UnlockConVars); AutoUpdateEnabled = m_json.value("AutoUpdateEnabled", AutoUpdateEnabled); AutoUpdateURL = m_json.value("AutoUpdateURL", AutoUpdateURL); + LogFilePath = m_json.value("LogFilePath", LogFilePath); } catch (const std::exception& ex) { diff --git a/src/core/coreconfig.h b/src/core/coreconfig.h index ab60a1558..01ac0bb3a 100644 --- a/src/core/coreconfig.h +++ b/src/core/coreconfig.h @@ -37,6 +37,7 @@ class CCoreConfig bool UnlockConVars = true; bool AutoUpdateEnabled = true; std::string AutoUpdateURL = std::string("http://gamedata.cssharp.dev"); + std::string LogFilePath; using json = nlohmann::json; CCoreConfig(const std::string& path); diff --git a/src/core/log.cpp b/src/core/log.cpp index 70db52d9c..75cde84cb 100644 --- a/src/core/log.cpp +++ b/src/core/log.cpp @@ -7,8 +7,9 @@ namespace counterstrikesharp { std::shared_ptr Log::m_core_logger; -void Log::Init() +void Log::Init(const std::string& logFilePath) { + const std::string resolvedLogFilePath = logFilePath.empty() ? "counterstrikesharp.log" : logFilePath; std::vector log_sinks; auto color_sink = std::make_shared(); #if _WIN32 @@ -18,7 +19,7 @@ void Log::Init() #endif log_sinks.emplace_back(color_sink); - log_sinks.emplace_back(std::make_shared("counterstrikesharp.log", true)); + log_sinks.emplace_back(std::make_shared(resolvedLogFilePath, true)); log_sinks[0]->set_pattern("%^[%T.%e] %n: %v%$"); log_sinks[1]->set_pattern("[%T.%e] [%l] %n: %v"); diff --git a/src/core/log.h b/src/core/log.h index 21c762cb8..4e0373310 100644 --- a/src/core/log.h +++ b/src/core/log.h @@ -1,6 +1,7 @@ #pragma once #include +#include #include #include @@ -9,7 +10,7 @@ namespace counterstrikesharp { class Log { public: - static void Init(); + static void Init(const std::string& logFilePath = ""); static void Close(); static std::shared_ptr& GetCoreLogger() { return m_core_logger; } diff --git a/src/mm_plugin.cpp b/src/mm_plugin.cpp index 1c611badc..ec344b618 100644 --- a/src/mm_plugin.cpp +++ b/src/mm_plugin.cpp @@ -135,6 +135,9 @@ bool CounterStrikeSharpMMPlugin::Load(PluginId id, ISmmAPI* ismm, char* error, s return false; } + Log::Close(); + Log::Init(globals::coreConfig->LogFilePath); + CSSHARP_CORE_INFO("CoreConfig loaded."); if (globals::coreConfig->AutoUpdateEnabled)