Configuration::Configuration() :
Daemon( false ),
+ LoggingLevel( LogLevel_ERROR ),
ConfigFileName( "" ),
SourceNetworkInterface( "" ),
NameServer( "" ),
Daemon = daemon;
}
+LogLevel Configuration::get_log_level() const
+{
+ return LoggingLevel;
+}
+
+void Configuration::set_log_level( const LogLevel &log_level )
+{
+ BOOST_ASSERT( (LogLevel_First <= log_level) && (log_level <= LogLevel_Last) );
+
+ this->LoggingLevel = log_level;
+}
+
string Configuration::get_config_file_name() const
{
return ConfigFileName;
#include <boost/shared_ptr.hpp>
#include "config/host.h"
+#include "host/loglevel.h"
//-----------------------------------------------------------------------------
// Configuration
std::string get_config_file_name() const;
void set_config_file_name( const std::string &config_file_name );
+ LogLevel get_log_level() const;
+ void set_log_level( const LogLevel &log_level );
+
std::string get_nameserver() const;
void set_nameserver( const std::string &nameserver );
private:
bool Daemon;
+ LogLevel LoggingLevel;
std::string ConfigFileName;
std::string SourceNetworkInterface;
std::string NameServer;
#include "config/option/hostpingintervaloption.h"
#include "config/option/linkdownintervaloption.h"
#include "config/option/linkupintervaloption.h"
+#include "config/option/logleveloption.h"
#include "config/option/nameserveroption.h"
#include "config/option/pingfaillimitoption.h"
#include "config/option/sourcenetworkinterfaceoption.h"
ConfigurationOptionItem version( new VersionOption );
GenericOptions.push_back( version );
+ ConfigurationOptionItem log_level( new LogLevelOption );
+ GenericOptions.push_back( log_level );
+
ConfigurationOptionItem hosts_down_limit( new HostsDownLimitOption );
ConfigOptions.push_back( hosts_down_limit );
--- /dev/null
+/*
+ The software in this package is distributed under the GNU General
+ Public License version 2 (with a special exception described below).
+
+ A copy of GNU General Public License (GPL) is included in this distribution,
+ in the file COPYING.GPL.
+
+ As a special exception, if other files instantiate templates or use macros
+ or inline functions from this file, or you compile this file and link it
+ with other works to produce a work based on this file, this file
+ does not by itself cause the resulting work to be covered
+ by the GNU General Public License.
+
+ However the source code for this file must still be made available
+ in accordance with section (3) of the GNU General Public License.
+
+ This exception does not invalidate any other reasons why a work based
+ on this file might be covered by the GNU General Public License.
+ */
+
+#include "config/option/logleveloption.h"
+
+#include <iostream>
+
+#include <logfunc.hpp>
+
+#include "host/loglevel.h"
+
+using namespace std;
+using boost::program_options::value;
+using boost::program_options::variables_map;
+using I2n::Logger::GlobalLogger;
+
+//-----------------------------------------------------------------------------
+// LogLevelOption
+//-----------------------------------------------------------------------------
+
+/**
+ * @brief Default constructor.
+ */
+LogLevelOption::LogLevelOption() :
+ ConfigurationOption(
+ "log-level",
+ value<string>()->default_value( "ERROR" ),
+ "Level of the log messages."
+ )
+{
+}
+
+/**
+ * @brief Destructor.
+ */
+LogLevelOption::~LogLevelOption()
+{
+}
+
+bool LogLevelOption::parse(
+ const variables_map& vm,
+ Configuration *configuration
+)
+{
+ // log-level
+ if ( 1 <= vm.count( get_command_string() ) )
+ {
+ string log_level_string = vm[ get_command_string() ].as<string> ();
+ LogLevel log_level = get_log_level_from_string( log_level_string );
+ configuration->set_log_level( log_level );
+
+ GlobalLogger.info() << get_command_string() << "=" << log_level_string << endl;
+ return true;
+ }
+
+ return false;
+}
--- /dev/null
+/*
+ The software in this package is distributed under the GNU General
+ Public License version 2 (with a special exception described below).
+
+ A copy of GNU General Public License (GPL) is included in this distribution,
+ in the file COPYING.GPL.
+
+ As a special exception, if other files instantiate templates or use macros
+ or inline functions from this file, or you compile this file and link it
+ with other works to produce a work based on this file, this file
+ does not by itself cause the resulting work to be covered
+ by the GNU General Public License.
+
+ However the source code for this file must still be made available
+ in accordance with section (3) of the GNU General Public License.
+
+ This exception does not invalidate any other reasons why a work based
+ on this file might be covered by the GNU General Public License.
+ */
+
+#ifndef LOG_LEVEL_OPTION_H
+#define LOG_LEVEL_OPTION_H
+
+#include <boost/program_options.hpp>
+
+#include "config/option/configurationoption.h"
+
+//-----------------------------------------------------------------------------
+// LogLevelOption
+//-----------------------------------------------------------------------------
+
+/**
+ * @brief The log level option.
+ */
+class LogLevelOption : public ConfigurationOption
+{
+public:
+ LogLevelOption();
+ virtual ~LogLevelOption();
+
+ virtual bool parse(
+ const boost::program_options::variables_map &vm,
+ Configuration *configuration
+ );
+
+};
+
+#endif // LOG_LEVEL_OPTION_H
${CMAKE_SOURCE_DIR}/src/config/option/hostsdownlimitoption.cpp
${CMAKE_SOURCE_DIR}/src/config/option/linkdownintervaloption.cpp
${CMAKE_SOURCE_DIR}/src/config/option/linkupintervaloption.cpp
+ ${CMAKE_SOURCE_DIR}/src/config/option/logleveloption.cpp
${CMAKE_SOURCE_DIR}/src/config/option/nameserveroption.cpp
${CMAKE_SOURCE_DIR}/src/config/option/pingfaillimitoption.cpp
${CMAKE_SOURCE_DIR}/src/config/option/sourcenetworkinterfaceoption.cpp
${CMAKE_SOURCE_DIR}/src/config/option/statusnotifiercmdoption.cpp
${CMAKE_SOURCE_DIR}/src/config/option/versionoption.cpp
+ ${CMAKE_SOURCE_DIR}/src/host/loglevel.cpp
${CMAKE_SOURCE_DIR}/src/host/pingprotocol.cpp
)
${CMAKE_SOURCE_DIR}/src/config/option/hostsdownlimitoption.cpp
${CMAKE_SOURCE_DIR}/src/config/option/linkdownintervaloption.cpp
${CMAKE_SOURCE_DIR}/src/config/option/linkupintervaloption.cpp
+ ${CMAKE_SOURCE_DIR}/src/config/option/logleveloption.cpp
${CMAKE_SOURCE_DIR}/src/config/option/nameserveroption.cpp
${CMAKE_SOURCE_DIR}/src/config/option/pingfaillimitoption.cpp
${CMAKE_SOURCE_DIR}/src/config/option/sourcenetworkinterfaceoption.cpp
${CMAKE_SOURCE_DIR}/src/config/option/statusnotifiercmdoption.cpp
${CMAKE_SOURCE_DIR}/src/config/option/versionoption.cpp
+ ${CMAKE_SOURCE_DIR}/src/host/loglevel.cpp
${CMAKE_SOURCE_DIR}/src/host/pingprotocol.cpp
)
${CMAKE_SOURCE_DIR}/src/config/option/hostsdownlimitoption.cpp
${CMAKE_SOURCE_DIR}/src/config/option/linkdownintervaloption.cpp
${CMAKE_SOURCE_DIR}/src/config/option/linkupintervaloption.cpp
+ ${CMAKE_SOURCE_DIR}/src/config/option/logleveloption.cpp
${CMAKE_SOURCE_DIR}/src/config/option/nameserveroption.cpp
${CMAKE_SOURCE_DIR}/src/config/option/pingfaillimitoption.cpp
${CMAKE_SOURCE_DIR}/src/config/option/sourcenetworkinterfaceoption.cpp
${CMAKE_SOURCE_DIR}/src/config/option/statusnotifiercmdoption.cpp
${CMAKE_SOURCE_DIR}/src/config/option/versionoption.cpp
+ ${CMAKE_SOURCE_DIR}/src/host/loglevel.cpp
${CMAKE_SOURCE_DIR}/src/host/pingprotocol.cpp
)
#include <boost/shared_ptr.hpp>
#include <boost/test/unit_test.hpp>
+#include "host/loglevel.h"
#include "host/pingprotocol.h"
#include "config/configurationoptions.h"
// if this assert fails, you must add or remove one of the options in the
// test bellow
- BOOST_CHECK_EQUAL( options.size(), 4 ); // help, version, daemon and config-file
+ BOOST_CHECK_EQUAL( options.size(), 5 ); // help, version, daemon, config-file and log-level
BOOST_CHECK_EQUAL( option_present( options, "help" ), true );
BOOST_CHECK_EQUAL( option_present( options, "config-file" ), true );
BOOST_CHECK_EQUAL( option_present( options, "daemon" ), true );
BOOST_CHECK_EQUAL( option_present( options, "version" ), true );
+ BOOST_CHECK_EQUAL( option_present( options, "log-level" ), true );
}
BOOST_AUTO_TEST_CASE( get_configuration_options )
option_insert( "config-file", boost::any( std::string("pingcheck.conf") ), vm );
option_insert( "daemon", boost::any(), vm );
+ option_insert( "log-level", boost::any( std::string("EMERGENCY") ), vm );
ConfigurationOptions config_options;
Configuration configuration;
BOOST_CHECK_EQUAL( configuration.get_config_file_name(), "pingcheck.conf" );
BOOST_CHECK_EQUAL( configuration.get_daemon(), true );
+ BOOST_CHECK_EQUAL( configuration.get_log_level(), LogLevel_EMERGENCY );
}
BOOST_AUTO_TEST_CASE( parse_configuration_options )
option_clear_and_insert( "version", value, vm );
BOOST_CHECK_EQUAL( config_options.halt_on_generic_options( vm ), true );
+ option_clear_and_insert( "log-level", value, vm );
+ BOOST_CHECK_EQUAL( config_options.halt_on_generic_options( vm ), false );
+
option_clear_and_insert( "hosts-down-limit", value, vm );
BOOST_CHECK_EQUAL( config_options.halt_on_generic_options( vm ), false );