mirror of
https://github.com/MihailRis/voxelcore.git
synced 2026-10-13 15:01:49 +00:00
Merge pull request #911 from MihailRis/log-param
--log command line argument
This commit is contained in:
commit
07b59e6882
5 changed files with 25 additions and 8 deletions
|
|
@ -12,6 +12,7 @@ struct CoreParameters {
|
||||||
std::filesystem::path userFolder = ".";
|
std::filesystem::path userFolder = ".";
|
||||||
std::filesystem::path scriptFile;
|
std::filesystem::path scriptFile;
|
||||||
std::filesystem::path projectFolder;
|
std::filesystem::path projectFolder;
|
||||||
|
std::filesystem::path logFile;
|
||||||
std::string debugServerString;
|
std::string debugServerString;
|
||||||
int tps = 20;
|
int tps = 20;
|
||||||
int subProcessDepth = 0;
|
int subProcessDepth = 0;
|
||||||
|
|
|
||||||
|
|
@ -403,6 +403,7 @@ static int l_start_background_instance(lua::State* L) {
|
||||||
"--script", io::resolve(scriptPath).u8string(),
|
"--script", io::resolve(scriptPath).u8string(),
|
||||||
"--sub-depth", std::to_string(engine->getCoreParameters()
|
"--sub-depth", std::to_string(engine->getCoreParameters()
|
||||||
.subProcessDepth + 1),
|
.subProcessDepth + 1),
|
||||||
|
"--log", io::resolve(outputPath).u8string(),
|
||||||
};
|
};
|
||||||
args.emplace_back("--project");
|
args.emplace_back("--project");
|
||||||
args.emplace_back(io::resolve(engine->getProject().path).u8string());
|
args.emplace_back(io::resolve(engine->getProject().path).u8string());
|
||||||
|
|
@ -417,11 +418,9 @@ static int l_start_background_instance(lua::State* L) {
|
||||||
if (handle == -1) {
|
if (handle == -1) {
|
||||||
throw std::runtime_error("sub-processes limit exceeded");
|
throw std::runtime_error("sub-processes limit exceeded");
|
||||||
}
|
}
|
||||||
::processes[handle] = platform::new_engine_instance(
|
::processes[handle] =
|
||||||
std::move(args),
|
platform::new_engine_instance(std::move(args), "", true);
|
||||||
outputPath.empty() ? "" : io::resolve(outputPath),
|
|
||||||
true
|
|
||||||
);
|
|
||||||
return lua::pushinteger(L, handle);
|
return lua::pushinteger(L, handle);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
10
src/main.cpp
10
src/main.cpp
|
|
@ -7,6 +7,7 @@
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
|
|
||||||
|
using namespace std::literals;
|
||||||
static debug::Logger logger("main");
|
static debug::Logger logger("main");
|
||||||
|
|
||||||
static void sigterm_handler(int signum) {
|
static void sigterm_handler(int signum) {
|
||||||
|
|
@ -36,7 +37,14 @@ int main(int argc, char** argv) {
|
||||||
#ifdef NDEBUG
|
#ifdef NDEBUG
|
||||||
std::signal(SIGINT, sigterm_handler);
|
std::signal(SIGINT, sigterm_handler);
|
||||||
#endif
|
#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.u8string());
|
||||||
platform::configure_encoding();
|
platform::configure_encoding();
|
||||||
|
|
||||||
auto& engine = Engine::getInstance();
|
auto& engine = Engine::getInstance();
|
||||||
|
|
|
||||||
|
|
@ -82,6 +82,10 @@ static bool perform_keyword(
|
||||||
params.subProcessDepth = reader.nextInt();
|
params.subProcessDepth = reader.nextInt();
|
||||||
return true;
|
return true;
|
||||||
}, "<depth>", "sub-process depth"),
|
}, "<depth>", "sub-process depth"),
|
||||||
|
ArgC("--log", [](auto& params, auto& reader) -> bool {
|
||||||
|
params.logFile = reader.next();
|
||||||
|
return true;
|
||||||
|
}, "<file>", "target log file"),
|
||||||
ArgC("--help", [](auto&, auto&) -> bool {
|
ArgC("--help", [](auto&, auto&) -> bool {
|
||||||
std::cout << "VoxelCore v" << ENGINE_VERSION_STRING << "\n\n";
|
std::cout << "VoxelCore v" << ENGINE_VERSION_STRING << "\n\n";
|
||||||
std::cout << "Command-line arguments:\n";
|
std::cout << "Command-line arguments:\n";
|
||||||
|
|
|
||||||
|
|
@ -28,6 +28,8 @@
|
||||||
#include <sys/wait.h>
|
#include <sys/wait.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
using namespace std::literals;
|
||||||
|
|
||||||
namespace platform::internal {
|
namespace platform::internal {
|
||||||
std::filesystem::path get_executable_path();
|
std::filesystem::path get_executable_path();
|
||||||
}
|
}
|
||||||
|
|
@ -356,7 +358,7 @@ std::unique_ptr<Process> platform::new_engine_instance(
|
||||||
if (!outputFile.empty()) {
|
if (!outputFile.empty()) {
|
||||||
si.dwFlags |= STARTF_USESTDHANDLES;
|
si.dwFlags |= STARTF_USESTDHANDLES;
|
||||||
si.hStdOutput = CreateFileW(
|
si.hStdOutput = CreateFileW(
|
||||||
toWString(outputFile.u8string()).data(),
|
toWString(outputFile.empty() ? outputFile.u8string() : "NUL"s).data(),
|
||||||
GENERIC_WRITE,
|
GENERIC_WRITE,
|
||||||
FILE_SHARE_WRITE | FILE_SHARE_READ,
|
FILE_SHARE_WRITE | FILE_SHARE_READ,
|
||||||
nullptr,
|
nullptr,
|
||||||
|
|
@ -434,9 +436,12 @@ std::unique_ptr<Process> platform::new_engine_instance(
|
||||||
if (subProcess) {
|
if (subProcess) {
|
||||||
pid_t pid = fork();
|
pid_t pid = fork();
|
||||||
|
|
||||||
|
if (outputFile.empty()) {
|
||||||
|
outputFile = "/dev/null";
|
||||||
|
}
|
||||||
int fd = open(
|
int fd = open(
|
||||||
outputFile.string().c_str(), O_WRONLY | O_CREAT | O_TRUNC, 0644
|
outputFile.string().c_str(), O_WRONLY | O_CREAT | O_TRUNC, 0644
|
||||||
);
|
);
|
||||||
|
|
||||||
if (pid == 0) {
|
if (pid == 0) {
|
||||||
prctl(PR_SET_PDEATHSIG, SIGTERM);
|
prctl(PR_SET_PDEATHSIG, SIGTERM);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue