mirror of
https://github.com/DarkflameUniverse/DarkflameServer.git
synced 2026-10-01 02:13:44 +00:00
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>
This commit is contained in:
@@ -5,17 +5,18 @@
|
||||
#include "Logger.h"
|
||||
#include "dConfig.h"
|
||||
|
||||
void Server::SetupLogger(const std::string_view serviceName) {
|
||||
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;
|
||||
}
|
||||
|
||||
const auto logsDir = BinaryPathFinder::GetBinaryDir() / "logs";
|
||||
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() + "_" + std::to_string(time(nullptr)) + ".log";
|
||||
std::string logPath = (logsDir / serviceName).string() + ".log";
|
||||
bool logToConsole = false;
|
||||
bool logDebugStatements = false;
|
||||
#ifdef _DEBUG
|
||||
|
||||
@@ -4,7 +4,8 @@
|
||||
#include <string_view>
|
||||
|
||||
namespace Server {
|
||||
void SetupLogger(const std::string_view serviceName);
|
||||
// takes in an optional argument of folder should you want to place the logs in a sub-folder
|
||||
void SetupLogger(const std::string_view serviceName, const std::string_view folder = "");
|
||||
};
|
||||
|
||||
#endif //!__SERVER__H__
|
||||
|
||||
Reference in New Issue
Block a user