* add --logfile option

This commit is contained in:
hagen 2016-02-01 00:00:00 +00:00
parent 0c56cd63bd
commit d2d4fa29e4
2 changed files with 14 additions and 10 deletions

View File

@ -111,6 +111,7 @@ namespace config {
("tunconf", value<std::string>()->default_value(""), "Path to config with tunnels list and options (default: try ~/.i2pd/tunnels.cfg or /var/lib/i2pd/tunnels.cfg)")
("pidfile", value<std::string>()->default_value(""), "Write pidfile to given path")
("log", value<bool>()->zero_tokens(), "Write logs to file instead stdout")
("logfile", value<std::string>()->default_value(""), "Path to logfile (stdout if not set, autodetect if daemon)")
("loglevel", value<std::string>()->default_value("info"), "Set the minimal level of log messages (debug, info, warn, error)")
("host", value<std::string>()->default_value(""), "External IP (deprecated)")
("port,p", value<uint16_t>()->default_value(4567), "Port to listen for incoming connections")

View File

@ -116,22 +116,25 @@ namespace i2p
bool Daemon_Singleton::start()
{
// initialize log
if (isLogging)
{
if (isDaemon)
{
std::string logfile_path = IsService () ? "/var/log" : i2p::util::filesystem::GetDataDir().string();
// set default to stdout
std::string logfile = ""; i2p::config::GetOption("logfile", logfile);
std::string loglevel = ""; i2p::config::GetOption("loglevel", loglevel);
if (isDaemon && logfile == "") {
// can't log to stdout, use autodetect of logfile
if (IsService ()) {
logfile = "/var/log";
} else {
logfile = i2p::util::filesystem::GetDataDir().string();
}
#ifndef _WIN32
logfile_path.append("/i2pd.log");
logfile.append("/i2pd.log");
#else
logfile_path.append("\\i2pd.log");
logfile.append("\\i2pd.log");
#endif
StartLog (logfile_path);
} else {
StartLog (""); // write to stdout
}
std::string loglevel; i2p::config::GetOption("loglevel", loglevel);
StartLog (logfile);
g_Log->SetLogLevel(loglevel);
}