mirror of
https://github.com/MihailRis/voxelcore.git
synced 2026-10-06 11:31: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 scriptFile;
|
||||
std::filesystem::path projectFolder;
|
||||
std::filesystem::path logFile;
|
||||
std::string debugServerString;
|
||||
int tps = 20;
|
||||
int subProcessDepth = 0;
|
||||
|
|
|
|||
|
|
@ -403,6 +403,7 @@ static int l_start_background_instance(lua::State* L) {
|
|||
"--script", io::resolve(scriptPath).u8string(),
|
||||
"--sub-depth", std::to_string(engine->getCoreParameters()
|
||||
.subProcessDepth + 1),
|
||||
"--log", io::resolve(outputPath).u8string(),
|
||||
};
|
||||
args.emplace_back("--project");
|
||||
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) {
|
||||
throw std::runtime_error("sub-processes limit exceeded");
|
||||
}
|
||||
::processes[handle] = platform::new_engine_instance(
|
||||
std::move(args),
|
||||
outputPath.empty() ? "" : io::resolve(outputPath),
|
||||
true
|
||||
);
|
||||
::processes[handle] =
|
||||
platform::new_engine_instance(std::move(args), "", true);
|
||||
|
||||
return lua::pushinteger(L, handle);
|
||||
}
|
||||
|
||||
|
|
|
|||
10
src/main.cpp
10
src/main.cpp
|
|
@ -7,6 +7,7 @@
|
|||
#include <iostream>
|
||||
#include <stdexcept>
|
||||
|
||||
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.u8string());
|
||||
platform::configure_encoding();
|
||||
|
||||
auto& engine = Engine::getInstance();
|
||||
|
|
|
|||
|
|
@ -82,6 +82,10 @@ static bool perform_keyword(
|
|||
params.subProcessDepth = reader.nextInt();
|
||||
return true;
|
||||
}, "<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 {
|
||||
std::cout << "VoxelCore v" << ENGINE_VERSION_STRING << "\n\n";
|
||||
std::cout << "Command-line arguments:\n";
|
||||
|
|
|
|||
|
|
@ -28,6 +28,8 @@
|
|||
#include <sys/wait.h>
|
||||
#endif
|
||||
|
||||
using namespace std::literals;
|
||||
|
||||
namespace platform::internal {
|
||||
std::filesystem::path get_executable_path();
|
||||
}
|
||||
|
|
@ -356,7 +358,7 @@ std::unique_ptr<Process> platform::new_engine_instance(
|
|||
if (!outputFile.empty()) {
|
||||
si.dwFlags |= STARTF_USESTDHANDLES;
|
||||
si.hStdOutput = CreateFileW(
|
||||
toWString(outputFile.u8string()).data(),
|
||||
toWString(outputFile.empty() ? outputFile.u8string() : "NUL"s).data(),
|
||||
GENERIC_WRITE,
|
||||
FILE_SHARE_WRITE | FILE_SHARE_READ,
|
||||
nullptr,
|
||||
|
|
@ -434,9 +436,12 @@ std::unique_ptr<Process> platform::new_engine_instance(
|
|||
if (subProcess) {
|
||||
pid_t pid = fork();
|
||||
|
||||
if (outputFile.empty()) {
|
||||
outputFile = "/dev/null";
|
||||
}
|
||||
int fd = open(
|
||||
outputFile.string().c_str(), O_WRONLY | O_CREAT | O_TRUNC, 0644
|
||||
);
|
||||
);
|
||||
|
||||
if (pid == 0) {
|
||||
prctl(PR_SET_PDEATHSIG, SIGTERM);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue