- daemon: run the application as a daemon.
- log-level: apply a filter of which log messages will be printed. The available
options are the default Unix levels (e.g. debug, info, etc.).
+- log-output: select the place where the log messages will be printed. The available
+ options are CONSOLE, TERMINAL and SYSLOG.
config/option/linkdownintervaloption.cpp
config/option/linkupintervaloption.cpp
config/option/logleveloption.cpp
+ config/option/logoutputoption.cpp
config/option/nameserveroption.cpp
config/option/pingfaillimitoption.cpp
config/option/sourcenetworkinterfaceoption.cpp
dns/timetolive.cpp
host/hoststatus.cpp
host/loglevel.cpp
+ host/logoutput.cpp
host/messagepayload.cpp
host/networkinterfacelist.cpp
host/pinger.cpp
Configuration::Configuration() :
Daemon( false ),
LoggingLevel( LogLevel::Error ),
+ LoggingOutput( LogOutput_SYSLOG ),
ConfigFileName( "" ),
SourceNetworkInterface( "" ),
NameServer( "" ),
this->LoggingLevel = log_level;
}
+LogOutput Configuration::get_log_output() const
+{
+ return LoggingOutput;
+}
+
+void Configuration::set_log_output( const LogOutput &log_output )
+{
+ BOOST_ASSERT( (LogOutput_First <= log_output) && (log_output <= LogOutput_Last) );
+
+ this->LoggingOutput = log_output;
+}
+
string Configuration::get_config_file_name() const
{
return ConfigFileName;
#include <string>
#include <vector>
+#include <logfunc.hpp>
+
#include <boost/shared_ptr.hpp>
-#include "logfunc.hpp"
#include "config/host.h"
#include "host/loglevel.h"
+#include "host/logoutput.h"
//-----------------------------------------------------------------------------
// Configuration
I2n::Logger::LogLevel get_log_level() const;
void set_log_level( const I2n::Logger::LogLevel &log_level );
+ LogOutput get_log_output() const;
+ void set_log_output( const LogOutput &log_output );
+
std::string get_nameserver() const;
void set_nameserver( const std::string &nameserver );
private:
bool Daemon;
I2n::Logger::LogLevel LoggingLevel;
+ LogOutput LoggingOutput;
std::string ConfigFileName;
std::string SourceNetworkInterface;
std::string NameServer;
#include "config/option/linkdownintervaloption.h"
#include "config/option/linkupintervaloption.h"
#include "config/option/logleveloption.h"
+#include "config/option/logoutputoption.h"
#include "config/option/nameserveroption.h"
#include "config/option/pingfaillimitoption.h"
#include "config/option/sourcenetworkinterfaceoption.h"
ConfigurationOptionItem log_level( new LogLevelOption );
GenericOptions.push_back( log_level );
+ ConfigurationOptionItem log_output( new LogOutputOption );
+ GenericOptions.push_back( log_output );
+
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/logoutputoption.h"
+
+#include <iostream>
+
+#include <logfunc.hpp>
+
+#include "host/logoutput.h"
+
+using namespace std;
+using boost::program_options::value;
+using boost::program_options::variables_map;
+using I2n::Logger::GlobalLogger;
+
+//-----------------------------------------------------------------------------
+// LogOutputOption
+//-----------------------------------------------------------------------------
+
+/**
+ * @brief Default constructor.
+ */
+LogOutputOption::LogOutputOption() :
+ ConfigurationOption(
+ "log-output",
+ value<string>()->default_value( "syslog" ),
+ "The place where to log the messages."
+ )
+{
+}
+
+/**
+ * @brief Destructor.
+ */
+LogOutputOption::~LogOutputOption()
+{
+}
+
+bool LogOutputOption::parse(
+ const variables_map& vm,
+ Configuration *configuration
+)
+{
+ // log-output
+ if ( 1 <= vm.count( get_command_string() ) )
+ {
+ string output_string = vm[ get_command_string() ].as<string> ();
+ LogOutput output = get_log_output_from_string( output_string );
+ configuration->set_log_output( output );
+
+ GlobalLogger.info() << get_command_string() << "=" << output_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_OUTPUT_OPTION_H
+#define LOG_OUTPUT_OPTION_H
+
+#include <boost/program_options.hpp>
+
+#include "config/option/configurationoption.h"
+
+//-----------------------------------------------------------------------------
+// LogOutputOption
+//-----------------------------------------------------------------------------
+
+/**
+ * @brief The log output option.
+ */
+class LogOutputOption : public ConfigurationOption
+{
+public:
+ LogOutputOption();
+ virtual ~LogOutputOption();
+
+ virtual bool parse(
+ const boost::program_options::variables_map &vm,
+ Configuration *configuration
+ );
+
+};
+
+#endif // LOG_OUTPUT_OPTION_H
--- /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 "host/logoutput.h"
+
+#include <algorithm>
+#include <map>
+
+#include <boost/assert.hpp>
+
+using namespace std;
+
+//-----------------------------------------------------------------------------
+// LogOutput
+//-----------------------------------------------------------------------------
+
+static map<string, LogOutput> log_output_string_map;
+
+/**
+ * @brief Transform the @a log_output_string into a @c LogOutput.
+ *
+ * @param log_output_string The string to be parsed.
+ *
+ * @return The @c LogOutput corresponding to the @a log_output_string.
+ */
+LogOutput get_log_output_from_string( const string &log_output_string )
+{
+ BOOST_ASSERT( !log_output_string.empty() );
+
+ // convert to uppercase to allow the protocol to be case insensitive
+ string log_output_uppercase_string( log_output_string );
+ transform( log_output_string.begin(), log_output_string.end(),
+ log_output_uppercase_string.begin(),
+ ::toupper ); //lint !e534
+
+ // TODO move to an init method
+ log_output_string_map[ "SYSLOG" ] = LogOutput_SYSLOG;
+ log_output_string_map[ "TERMINAL" ] = LogOutput_TERMINAL;
+ log_output_string_map[ "CONSOLE" ] = LogOutput_TERMINAL;
+
+ LogOutput protocol = log_output_string_map[ log_output_uppercase_string ];
+
+ return protocol;
+}
--- /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_OUTPUT_H
+#define LOG_OUTPUT_H
+
+#include <string>
+
+//-----------------------------------------------------------------------------
+// LogOutput
+//-----------------------------------------------------------------------------
+
+enum LogOutput
+{
+ LogOutput_First = 0,
+ LogOutput_SYSLOG = LogOutput_First,
+ LogOutput_TERMINAL,
+ LogOutput_Last = LogOutput_TERMINAL
+};
+
+LogOutput get_log_output_from_string( const std::string &output_string );
+
+#endif // LOG_OUTPUT_H
using boost::shared_ptr;
using I2n::Logger::GlobalLogger;
-
//-----------------------------------------------------------------------------
// Declarations
//-----------------------------------------------------------------------------
ConfigurationItem get_configuration(int, const char**);
LinkStatusItem get_status_notifier(const ConfigurationItem&);
void init_logger();
+void set_log_output(const ConfigurationItem &);
void init_pingers(const ConfigurationItem&, const LinkStatusItem&, PingSchedulerList*);
void start_pingers(const PingSchedulerList&);
void stop_pingers(const PingSchedulerList&);
I2n::Logger::set_log_level( default_log_level ); //lint !e534
}
+void set_log_output(
+ const ConfigurationItem &configuration
+)
+{
+ LogOutput log_output = configuration->get_log_output();
+ switch (log_output)
+ {
+ case LogOutput_SYSLOG:
+ I2n::Logger::enable_syslog(true);
+ I2n::Logger::enable_stderr_log(false);
+ I2n::Logger::enable_log_file(false);
+ break;
+ case LogOutput_TERMINAL:
+ I2n::Logger::enable_syslog(false);
+ I2n::Logger::enable_stderr_log(true);
+ I2n::Logger::enable_log_file(false);
+ break;
+ }
+}
+
void init_pingers(
const ConfigurationItem &configuration,
const LinkStatusItem &status_notifier,
int log_level = configuration->get_log_level();
I2n::Logger::set_log_level( log_level ); //lint !e534
+ set_log_output( configuration );
+
bool daemon_mode = configuration->get_daemon();
if ( daemon_mode )
{