Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/core/coreconfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
1 change: 1 addition & 0 deletions src/core/coreconfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
5 changes: 3 additions & 2 deletions src/core/log.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@
namespace counterstrikesharp {
std::shared_ptr<spdlog::logger> 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<spdlog::sink_ptr> log_sinks;
auto color_sink = std::make_shared<spdlog::sinks::stderr_color_sink_mt>();
#if _WIN32
Expand All @@ -18,7 +19,7 @@ void Log::Init()
#endif

log_sinks.emplace_back(color_sink);
log_sinks.emplace_back(std::make_shared<spdlog::sinks::basic_file_sink_mt>("counterstrikesharp.log", true));
log_sinks.emplace_back(std::make_shared<spdlog::sinks::basic_file_sink_mt>(resolvedLogFilePath, true));

log_sinks[0]->set_pattern("%^[%T.%e] %n: %v%$");
log_sinks[1]->set_pattern("[%T.%e] [%l] %n: %v");
Expand Down
3 changes: 2 additions & 1 deletion src/core/log.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#pragma once

#include <memory>
#include <string>

#include <spdlog/fmt/ostr.h>
#include <spdlog/spdlog.h>
Expand All @@ -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<spdlog::logger>& GetCoreLogger() { return m_core_logger; }
Expand Down
3 changes: 3 additions & 0 deletions src/mm_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down