#include <boost/assert.hpp>
#include <boost/foreach.hpp>
+#include <logfunc.hpp>
+
using namespace std;
using boost::program_options::command_line_parser;
using boost::program_options::options_description;
using boost::program_options::positional_options_description;
using boost::program_options::value;
using boost::program_options::variables_map;
+using I2n::Logger::GlobalLogger;
//-----------------------------------------------------------------------------
// ConfigurationReader
// daemon
bool have_daemon = ( vm.count( DaemonCmdStr ) > 0 );
Config.set_daemon( have_daemon );
- cout << DaemonCmdStr << "=" << have_daemon << endl;
+ GlobalLogger.info() << DaemonCmdStr << "="
+ << have_daemon << endl;
// config-file
if ( vm.count( ConfigFileCmdStr ) > 0 )
string config_file_name = vm[ ConfigFileCmdStr ].as<string> ();
Config.set_config_file_name( config_file_name );
- cout << ConfigFileCmdStr << "=" << config_file_name << endl;
+ GlobalLogger.info() << ConfigFileCmdStr << "="
+ << config_file_name << endl;
}
return false;
vm[ SourceNetworkInterfaceCmdStr ].as<string> ();
Config.set_source_network_interface( source_network_interface );
- cout << SourceNetworkInterfaceCmdStr << "=" << source_network_interface
- << endl;
+ GlobalLogger.info() << SourceNetworkInterfaceCmdStr << "="
+ << source_network_interface << endl;
}
// nameserver
string nameserver = vm[ NameServerCmdStr ].as<string> ();
Config.set_nameserver( nameserver );
- cout << NameServerCmdStr << "=" << nameserver << endl;
+ GlobalLogger.info() << NameServerCmdStr << "="
+ << nameserver << endl;
}
// hosts-down-limit
host_down_limit = vm[ HostsDownLimitCmdStr ].as<int> ();
Config.set_hosts_down_limit( host_down_limit );
- cout << HostsDownLimitCmdStr << "=" << host_down_limit << endl;
+ GlobalLogger.info() << HostsDownLimitCmdStr << "="
+ << host_down_limit << endl;
}
// ping-fail-limit
int ping_fail_limit = vm[ PingFailLimitCmdStr ].as<int> ();
Config.set_ping_fail_limit( ping_fail_limit );
- cout << PingFailLimitCmdStr << "=" << ping_fail_limit << endl;
+ GlobalLogger.info() << PingFailLimitCmdStr << "="
+ << ping_fail_limit << endl;
}
// status-notifier-cmd
string status_notifier_cmd = vm[ StatusNotifierCmdCmdStr ].as<string>();
Config.set_status_notifier_cmd( status_notifier_cmd );
- cout << StatusNotifierCmdCmdStr << "=" << status_notifier_cmd << endl;
+ GlobalLogger.info() << StatusNotifierCmdCmdStr << "="
+ << status_notifier_cmd << endl;
}
// link-up-interval
int link_up_interval_in_min = vm[ LinkUpIntervalCmdStr ].as<int>();
Config.set_link_up_interval_in_min( link_up_interval_in_min );
- cout << LinkUpIntervalCmdStr << "=" << link_up_interval_in_min
- << endl;
+ GlobalLogger.info() << LinkUpIntervalCmdStr << "="
+ << link_up_interval_in_min << endl;
}
// [host] name
HostItem host_item( new Host( host_name ) );
hosts_list.push_back( host_item );
- cout << HostNameCmdStr << "=" << host_name << endl;
+ GlobalLogger.info() << HostNameCmdStr << "="
+ << host_name << endl;
}
Config.set_hosts( hosts_list );
host_item->set_interval_in_sec( host_interval_in_sec );
++hosts_it;
- cout << HostIntervalCmdStr << "=" << host_interval_in_sec << endl;
+ GlobalLogger.info() << HostIntervalCmdStr << "="
+ << host_interval_in_sec << endl;
}
hosts_interval_count = hosts_intervals.size();
}
catch ( const std::exception &ex )
{
- cerr << ex.what() << endl;
+ GlobalLogger.error() << ex.what() << endl;
return false;
}
}
ifstream ifs( config_file_name.c_str() );
if ( !ifs )
{
- cerr << "Error: could not open " << config_file_name << " file."
- << endl;
+ GlobalLogger.error() << "Error: could not open "
+ << config_file_name << " file." << endl;
return false;
}
else
#include <boost/net/resolve.hpp>
#include <boost/shared_ptr.hpp>
+#include <logfunc.hpp>
+
#include "dns/hostaddress.h"
using namespace std;
using boost::net::dns::message;
using boost::net::dns::rr_list_t;
using boost::shared_ptr;
+using I2n::Logger::GlobalLogger;
//-----------------------------------------------------------------------------
// DnsResolver
BOOST_ASSERT( !HostDnsAddress.empty() );
BOOST_ASSERT( !NameServer.empty() );
- cout << "Resolved IP(s) for host : " << HostDnsAddress << endl;
+ GlobalLogger.info() << "Resolved IP(s) for host : "
+ << HostDnsAddress << endl;
try
{
int resolved_ip_count = answers_list.size();
if ( resolved_ip_count < 1 )
{
- cerr << "Error: host " << HostDnsAddress << " could not be resolved."
- << endl;
+ GlobalLogger.error() << "Error: host "
+ << HostDnsAddress << " could not be resolved." << endl;
return false;
}
}
catch ( const std::exception &ex )
{
- cerr << "Error: host " << HostDnsAddress << " could not be resolved. "
- << ex.what() << endl;
+ GlobalLogger.error() << "Error: host " << HostDnsAddress
+ << " could not be resolved. " << ex.what() << endl;
return false;
}
HostAddress resolved_host( ip, ttl );
resolved_host_address_list->push_back( resolved_host );
- cout << "- " << ip << " [" << ttl << "s]" << endl;
+ GlobalLogger.info() << "- " << ip
+ << " [" << ttl << "s]" << endl;
}
}
#include <boost/date_time/posix_time/posix_time.hpp>
#include <boost/date_time/posix_time/posix_time_types.hpp>
+#include <logfunc.hpp>
+
#include "icmp/icmpchecksumcalculator.h"
#include "icmp/icmpdata.h"
#include "icmp/icmpheader.h"
using boost::posix_time::microsec_clock;
using boost::posix_time::ptime;
using boost::posix_time::seconds;
+using I2n::Logger::GlobalLogger;
//-----------------------------------------------------------------------------
// BoostPinger
if ( !select_source_network_interface( source_network_interface ) )
{
- cerr << "Error: could not bind the socket with the local interface."
- << ::strerror( errno ) << endl;
+ GlobalLogger.error() << "Error: could not bind the socket "
+ "with the local interface." << ::strerror( errno ) << endl;
}
}
size_t bytes_sent = Socket.send_to( data, DestinationEndpoint );
if ( bytes_sent != buffer_size( data ) )
{
- cerr << "Error: fail sending ping data." << endl;
+ GlobalLogger.error() << "Error: fail sending ping data."
+ << endl;
}
}
catch ( const exception &ex )
{
- cerr << "Error: fail sending ping data. " << ex.what() << endl;
+ GlobalLogger.error() << "Error: fail sending ping data. "
+ << ex.what() << endl;
}
schedule_timeout_echo_reply();
void BoostPinger::print_request_timeout() const
{
- cout << "Request timed out" << endl;
+ GlobalLogger.info() << "Request timed out" << endl;
}
void BoostPinger::print_echo_reply(
time_resolution_traits_adapted64_impl::int_type elapsed_time =
(now - TimeSent).total_milliseconds();
- cout << bytes_received << " bytes "
+ GlobalLogger.info() << bytes_received << " bytes "
<< "from " << remote_address
<< ": icmp_seq=" << sequence_number
<< " ttl=" << ttl
string local_address = ipv4_hdr.get_destination_address().to_string();
uint16_t sequence_number = icmp_hdr.get_sequence_number();
- cout << "From " << local_address
+ GlobalLogger.info() << "From " << local_address
<< " icmp_seq=" << sequence_number
<< " Destination Net Unreachable" << endl;
}
#include <boost/bind.hpp>
+#include <logfunc.hpp>
+
#include "dns/dnsresolver.h"
#include "host/boostpinger.h"
#include "link/linkstatusanalyzer.h"
using boost::posix_time::ptime;
using boost::posix_time::seconds;
using boost::shared_ptr;
+using I2n::Logger::GlobalLogger;
//-----------------------------------------------------------------------------
// PingScheduler
// TODO this code is similar to the one at start_pinging(), make it simple!
if ( IpList.expired_resolved_ip() )
{
- cout << "Updating DNS ... "; // TODO
+ GlobalLogger.info() << "Updating DNS ... ";
bool address_resolved = resolve_ping_address();
if ( !address_resolved )
{
- cerr << "Error: could not update host IP, may use outdated address"
- << endl;
+ GlobalLogger.error() << "Error: could not update host "
+ "IP, may use outdated address" << endl;
}
}
{
PingIntervalInSec.speed_up();
- cout << "- Speeding up ping interval to: " << PingIntervalInSec
- << "s" << endl; // TODO output log
+ GlobalLogger.info() << "- Speeding up ping interval to: "
+ << PingIntervalInSec << "s" << endl;
}
else
{
PingIntervalInSec.back_to_original();
- cout << "- Stick to the original ping interval: " << PingIntervalInSec
- << "s" << endl; // TODO output log
+ GlobalLogger.info() << "- Stick to the original ping interval: "
+ << PingIntervalInSec << "s" << endl;
}
}
ptime now = microsec_clock::universal_time();
time_resolution_traits_adapted64_impl::int_type elapsed_time_in_sec =
(now - TimeSentLastPing).total_seconds();
- cout << "- Time elapsed since last ping: " << elapsed_time_in_sec << "s"
- << endl; // TODO output log
+ GlobalLogger.info() << "- Time elapsed since last ping: "
+ << elapsed_time_in_sec << "s" << endl;
TimeSentLastPing = microsec_clock::universal_time();
}
#include <boost/assert.hpp>
+#include <logfunc.hpp>
+
using namespace std;
using boost::posix_time::microsec_clock;
using boost::posix_time::ptime;
+using I2n::Logger::GlobalLogger;
//-----------------------------------------------------------------------------
// LinkStatusAnalyzer
{
BOOST_ASSERT( !host_address.empty() );
- cout << "- Host up: " << host_address << endl; // TODO
+ GlobalLogger.info() << "- Host up: " << host_address << endl;
add_host_up( host_address );
{
BOOST_ASSERT( !host_address.empty() );
- cout << "- Host down: " << host_address << endl; // TODO
+ GlobalLogger.info() << "- Host down: " << host_address << endl;
add_host_down( host_address );
#include <boost/assert.hpp>
+#include <logfunc.hpp>
#include <stringfunc.hxx>
using namespace std;
+using I2n::Logger::GlobalLogger;
//-----------------------------------------------------------------------------
// StatusNotifierCommand
string args = get_arguments_string();
string secure_command = app + " " + args;
- cout << "- Command: " << secure_command << endl; // TODO
+ GlobalLogger.info() << "- Command: " << secure_command
+ << endl;
int ret = system( secure_command.c_str() );
if ( ret != 0 )
#include <boost/foreach.hpp>
#include <boost/shared_ptr.hpp>
-#include "daemonfunc.hpp"
+#include <daemonfunc.hpp>
+#include <logfunc.hpp>
#include "config/configurationreader.h"
#include "config/host.h"
using namespace std;
using boost::asio::io_service;
using boost::shared_ptr;
+using I2n::Logger::GlobalLogger;
+
+void init_log()
+{
+ I2n::Logger::enable_syslog( I2n::Logger::Facility::User );
+ I2n::Logger::set_log_level( I2n::Logger::LogLevel::Notice );
+}
int main( int argc, char* argv[] )
{
+ init_log();
+
// TODO load_configuration() or read_configuration()
ConfigurationReader config_reader;
bool read_success = config_reader.parse( argc, argv );
bool started = scheduler->start_pinging();
if ( !started )
{
- cerr << "Error: could not start pinger." << endl;
+ GlobalLogger.error() << "Error: could not start pinger."
+ << endl;
}
}