warn in case of unrecognized command line options; added more info output concerning...
authorChristian Herdtweck <christian.herdtweck@intra2net.com>
Wed, 12 Nov 2014 10:08:26 +0000 (11:08 +0100)
committerChristian Herdtweck <christian.herdtweck@intra2net.com>
Wed, 12 Nov 2014 10:11:06 +0000 (11:11 +0100)
src/config/configurationcommandline.cpp
src/main.cpp

index 5f1330c..afce481 100644 (file)
@@ -33,6 +33,8 @@ using boost::program_options::options_description;
 using boost::program_options::parsed_options;
 using boost::program_options::positional_options_description;
 using boost::program_options::variables_map;
+using boost::program_options::collect_unrecognized;
+using boost::program_options::include_positional;
 using I2n::Logger::GlobalLogger;
 
 //-----------------------------------------------------------------------------
@@ -117,6 +119,17 @@ bool ConfigurationCommandLine::process( variables_map *vm )
                 positional( p ).
                 allow_unregistered().
                 run();
+
+        // TODO not sure whether the "allow_unregistered()" above is required or not
+        // Because of this option, it is easy to make mistakes in options, so at least
+        // warn
+        vector<string> unrecognized_options = collect_unrecognized(parsed_opt.options,
+                                                                   include_positional);
+        if ( !unrecognized_options.empty() )
+        {
+            GlobalLogger.warning() << "Accepted unrecognized options" << endl;
+        }
+
         store( parsed_opt, *vm );
         notify( *vm );
     }
index 979beef..a467405 100644 (file)
@@ -82,6 +82,11 @@ ConfigurationItem get_configuration(
         Configuration config_obj = config_reader.get_configuration();
         configuration.reset( new Configuration( config_obj ) );
     }
+    else
+    {
+        GlobalLogger.error() << "Failed to parse options from command line and/or config file! "
+           << "Continue with standard values." << endl;
+    }
 
     return configuration;
 }
@@ -108,6 +113,7 @@ LinkStatusItem get_status_notifier(
 
 void init_logger()
 {
+    // set default: log at level NOTICE to syslog
     const int default_log_level = I2n::Logger::LogLevel::Notice;
 
     I2n::Logger::enable_syslog( I2n::Logger::Facility::User ); //lint !e1786
@@ -122,14 +128,22 @@ void set_log_output(
     switch (log_output)
     {
     case LogOutput_SYSLOG:
+        GlobalLogger.info() << "Setting log output target to syslog" << endl;
         I2n::Logger::enable_syslog(true);
         I2n::Logger::enable_stderr_log(false);
         I2n::Logger::enable_log_file(false);
+        GlobalLogger.info() << "Set log output target to syslog" << endl;
         break;
     case LogOutput_TERMINAL:
+        GlobalLogger.info() << "Setting log output target to terminal" << endl;
         I2n::Logger::enable_syslog(false);
         I2n::Logger::enable_stderr_log(true);
         I2n::Logger::enable_log_file(false);
+        GlobalLogger.info() << "Set log output target to terminal" << endl;
+        GlobalLogger.info() << "(check syslog for earlier messages)" << endl;
+        break;
+    default:
+        GlobalLogger.error() << "Unknown log output target!" << endl;
         break;
     }
 }