Browse Source

* add --logfile option

pull/358/head
hagen 9 years ago
parent
commit
d2d4fa29e4
  1. 1
      Config.cpp
  2. 23
      Daemon.cpp

1
Config.cpp

@ -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)") ("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") ("pidfile", value<std::string>()->default_value(""), "Write pidfile to given path")
("log", value<bool>()->zero_tokens(), "Write logs to file instead stdout") ("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)") ("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)") ("host", value<std::string>()->default_value(""), "External IP (deprecated)")
("port,p", value<uint16_t>()->default_value(4567), "Port to listen for incoming connections") ("port,p", value<uint16_t>()->default_value(4567), "Port to listen for incoming connections")

23
Daemon.cpp

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

Loading…
Cancel
Save