From 7c9fff19e457e4d53d7bc68cb8d871ade80fb716 Mon Sep 17 00:00:00 2001 From: MihailRis Date: Mon, 3 Aug 2026 19:54:54 +0300 Subject: [PATCH] add '--log' command line parameter --- src/engine/CoreParameters.hpp | 1 + src/main.cpp | 10 +++++++++- src/util/command_line.cpp | 4 ++++ 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/engine/CoreParameters.hpp b/src/engine/CoreParameters.hpp index b5d8074ce..9668ce1cd 100644 --- a/src/engine/CoreParameters.hpp +++ b/src/engine/CoreParameters.hpp @@ -12,6 +12,7 @@ struct CoreParameters { std::filesystem::path userFolder = "."; std::filesystem::path scriptFile; std::filesystem::path projectFolder; + std::filesystem::path logFile; std::string debugServerString; int tps = 20; int subProcessDepth = 0; diff --git a/src/main.cpp b/src/main.cpp index 402b829b3..4e739acde 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -7,6 +7,7 @@ #include #include +using namespace std::literals; static debug::Logger logger("main"); static void sigterm_handler(int signum) { @@ -36,7 +37,14 @@ int main(int argc, char** argv) { #ifdef NDEBUG std::signal(SIGINT, sigterm_handler); #endif - debug::Logger::init(coreParameters.userFolder.string() + "/latest.log"); + std::filesystem::path logFile = coreParameters.logFile; + if (logFile.empty()) { + logFile = coreParameters.userFolder.string() + "/latest"s + + (coreParameters.subProcessDepth > 0 + ? ".sub" + std::to_string(coreParameters.subProcessDepth) + : "") + ".log"s; + } + debug::Logger::init(logFile); platform::configure_encoding(); auto& engine = Engine::getInstance(); diff --git a/src/util/command_line.cpp b/src/util/command_line.cpp index f05231821..d5435e955 100644 --- a/src/util/command_line.cpp +++ b/src/util/command_line.cpp @@ -82,6 +82,10 @@ static bool perform_keyword( params.subProcessDepth = reader.nextInt(); return true; }, "", "sub-process depth"), + ArgC("--log", [](auto& params, auto& reader) -> bool { + params.logFile = reader.next(); + return true; + }, "", "target log file"), ArgC("--help", [](auto&, auto&) -> bool { std::cout << "VoxelCore v" << ENGINE_VERSION_STRING << "\n\n"; std::cout << "Command-line arguments:\n";