Files
DarkflameServer/dServer/Server.cpp
David Markowitz 6f3a8d502f feat: logging structure improvements (#2037)
* feat: logging structure improvements

tested that logs are sorted by the folder argument and that the directories are created recursively.
tested that crash dumps follow the same exact name (+Crash_...name..._pid.log) so you can match the crash dump to the corresponding log file much easier

* Potential fix for pull request finding 'Use parsed cloneID when constructing the log folder'

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>

* const

---------

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
2026-09-26 21:35:58 -05:00

31 lines
928 B
C++

#include "Server.h"
#include "BinaryPathFinder.h"
#include "Game.h"
#include "Logger.h"
#include "dConfig.h"
void Server::SetupLogger(const std::string_view serviceName, const std::string_view folder) {
if (Game::logger) {
LOG("A logger has already been setup, skipping.");
return;
}
auto logsDir = BinaryPathFinder::GetBinaryDir() / "logs";
if (!folder.empty()) logsDir /= folder;
if (!std::filesystem::exists(logsDir)) std::filesystem::create_directories(logsDir);
std::string logPath = (logsDir / serviceName).string() + ".log";
bool logToConsole = false;
bool logDebugStatements = false;
#ifdef _DEBUG
logToConsole = true;
logDebugStatements = true;
#endif
Game::logger = new Logger(logPath, logToConsole, logDebugStatements);
Game::logger->SetLogToConsole(Game::config->GetValue("log_to_console") != "0");
Game::logger->SetLogDebugStatements(Game::config->GetValue("log_debug_statements") == "1");
}