From fcdd6e100d8067e584d10408e572165da53fe572 Mon Sep 17 00:00:00 2001 From: Alexey Milovidov Date: Tue, 23 Nov 2010 18:55:59 +0000 Subject: [PATCH] Daemon: added default parameters. --- libs/libcommon/src/daemon.cpp | 24 +++++++++--------------- 1 file changed, 9 insertions(+), 15 deletions(-) diff --git a/libs/libcommon/src/daemon.cpp b/libs/libcommon/src/daemon.cpp index 3126fcaae4c..85785cf9dce 100644 --- a/libs/libcommon/src/daemon.cpp +++ b/libs/libcommon/src/daemon.cpp @@ -50,12 +50,12 @@ void Daemon::reloadConfiguration() try { - if( !config().hasProperty("config-file") ) throw Yandex::BException("config-file and pid-file should be specified"); - //config().remove(Poco::Util::Application::PRIO_DEFAULT); - loadConfiguration(config().getString("config-file")); + loadConfiguration(config().getString("config-file", "config.xml")); + + bool log_to_console = !config().getBool("application.runAsDaemon", false); // Перейдём в каталожек, чтобы нормально писать логи и коры - if( config().hasProperty("logger.log") && !config().hasProperty("logger.console") ) + if(config().hasProperty("logger.log") && !log_to_console) { std::string path = Yandex::mkdir( config().getString("logger.log") ); if (config().getBool("application.runAsDaemon", false) @@ -111,7 +111,9 @@ void Daemon::buildLoggers() try { - if( config().hasProperty("logger.log") && !config().hasProperty("logger.console") ) + bool log_to_console = !config().getBool("application.runAsDaemon", false); + + if(config().hasProperty("logger.log") && !log_to_console) { std::cerr << "Should logs to " << config().getString("logger.log") << std::endl; @@ -163,7 +165,7 @@ void Daemon::buildLoggers() ConsoleChannel *file = new ConsoleChannel(); logger().close(); logger().setChannel( file ); - logger().warning("Log file isn't specified. Logging to console"); + logger().warning("Logging to console"); } } catch(...) @@ -217,8 +219,7 @@ void Daemon::initialize(Application& self) ServerApplication::initialize(self); // Создадим pid-file - if( !config().hasProperty("pid") ) throw Yandex::BException("config-file and pid-file should be specified"); - m_Pid.seed( config().getString("pid") ); + m_Pid.seed(config().getString("pid", "pid")); // Считаем конфигурацию reloadConfiguration(); @@ -288,11 +289,4 @@ void Daemon::defineOptions(Poco::Util::OptionSet& _options) .argument ("") .binding("pid") ); - - _options.addOption( - Poco::Util::Option ("console", "", "print logs on console only") - .required (false) - .repeatable (false) - .binding("logger.console") - ); }