[Server] Add "--no-logs" option

0.6.1
Koncord 8 years ago
parent dbb636ac90
commit b3b7003313

@ -159,8 +159,9 @@ boost::program_options::variables_map launchOptions(int argc, char *argv[], File
bpo::options_description desc; bpo::options_description desc;
desc.add_options() desc.add_options()
("resources", bpo::value<Files::EscapeHashString>()->default_value("resources"), ("resources", bpo::value<Files::EscapeHashString>()->default_value("resources"), "set resources directory")
"set resources directory"); ("no-logs", bpo::value<bool>()->implicit_value(true)->default_value(false),
"Do not write logs. Useful for daemonizing.");
cfgMgr.readConfiguration(variables, desc, true); cfgMgr.readConfiguration(variables, desc, true);
@ -202,14 +203,19 @@ int main(int argc, char *argv[])
boost::filesystem::ofstream logfile; boost::filesystem::ofstream logfile;
// Redirect cout and cerr to tes3mp server log if (!variables["no-logs"].as<bool>())
logfile.open (boost::filesystem::path(cfgMgr.getLogPath() / "/tes3mp-server-" += Log::getFilenameTimestamp() += ".log")); {
// Redirect cout and cerr to tes3mp server log
logfile.open(boost::filesystem::path(
cfgMgr.getLogPath() / "/tes3mp-server-" += Log::getFilenameTimestamp() += ".log"));
coutsb.open (Tee(logfile, oldcout)); coutsb.open(Tee(logfile, oldcout));
cerrsb.open (Tee(logfile, oldcerr)); cerrsb.open(Tee(logfile, oldcerr));
std::cout.rdbuf (&coutsb); std::cout.rdbuf(&coutsb);
std::cerr.rdbuf (&cerrsb); std::cerr.rdbuf(&cerrsb);
}
LOG_INIT(logLevel); LOG_INIT(logLevel);
@ -295,9 +301,12 @@ int main(int argc, char *argv[])
if (code == 0) if (code == 0)
LOG_MESSAGE_SIMPLE(Log::LOG_INFO, "Quitting peacefully."); LOG_MESSAGE_SIMPLE(Log::LOG_INFO, "Quitting peacefully.");
// Restore cout and cerr if(!variables["no-logs"].as<bool>())
std::cout.rdbuf(cout_rdbuf); {
std::cerr.rdbuf(cerr_rdbuf); // Restore cout and cerr
std::cout.rdbuf(cout_rdbuf);
std::cerr.rdbuf(cerr_rdbuf);
}
breakpad_close(); breakpad_close();
return code; return code;

Loading…
Cancel
Save