Clean up output, whitespace,
authorChristian Herdtweck <christian.herdtweck@intra2net.com>
Mon, 12 Jan 2015 14:33:48 +0000 (15:33 +0100)
committerChristian Herdtweck <christian.herdtweck@intra2net.com>
Mon, 12 Jan 2015 14:33:48 +0000 (15:33 +0100)
* there were several cases of GlobalLogger.error() << "Error: ..." which is redundant
* there was one instance of streaming to cerr instead of GlobalLogger.error
* remove trailing whitespace

15 files changed:
src/config/configurationcommandline.cpp
src/config/option/ratiorandomhostsoption.h
src/dns/dnsresolver.cpp
src/host/messagepayload.cpp
src/host/networkinterface.hpp
src/host/networkinterfacelist.cpp
src/host/pingerfactory.cpp
src/host/pingscheduler.cpp
src/icmp/icmppacketfactory.cpp
src/icmp/icmpv4packet.cpp
src/icmp/icmpv6packet.cpp
src/ip/ipv4header.cpp
src/main.cpp
src/tcp/tcppinger.cpp
src/tcp/tcpsegmentfactory.cpp

index 2acd73a..cf5381c 100644 (file)
@@ -121,12 +121,6 @@ bool ConfigurationCommandLine::process( variables_map *vm )
     catch ( const std::exception &ex )
     {
         GlobalLogger.error() << "Error parsing command line options: " << ex.what() << endl;
-
-        if (true) // TODO: if GlobalLogger is not logging to console
-        {   // ensure that error about command line options shows on command line
-            cerr << "Error parsing command line options: " << ex.what() << endl;
-        }
-
         return false;
     }
 
index 793e4c8..479caa2 100644 (file)
@@ -30,7 +30,7 @@
 //-----------------------------------------------------------------------------
 
 /**
- * @brief This class represents the ""Ratio in (0,1] of hosts to use, picking 
+ * @brief This class represents the ""Ratio in (0,1] of hosts to use, picking
  * them at random from host list" configuration option.
  */
 class RatioRandomHostsOption : public ConfigurationOption
index 83615d6..cf997b1 100644 (file)
@@ -103,7 +103,7 @@ bool DnsResolver::resolve()
         size_t resolved_ip_count = answers_list.size();
         if ( resolved_ip_count < 1 )
         {
-            GlobalLogger.error() << "Error: IP host " << HostDnsAddress << " could not be resolved." << endl;
+            GlobalLogger.error() << "IP host " << HostDnsAddress << " could not be resolved." << endl;
             return false;
         }
 
@@ -113,7 +113,7 @@ bool DnsResolver::resolve()
     }
     catch ( const std::exception &ex )
     {
-        GlobalLogger.error() << "Error: host " << HostDnsAddress << " could not be resolved. "
+        GlobalLogger.error() << "Host " << HostDnsAddress << " could not be resolved. "
                 << ex.what() << endl;
         return false;
     }
@@ -237,7 +237,7 @@ rr_list_t DnsResolver::get_answers_list(
     }
     catch ( const std::exception &ex )
     {
-        GlobalLogger.error() << "Error: name server " << name_server << " does not seem to be an IP address. ";
+        GlobalLogger.error() << "Name server " << name_server << " does not seem to be an IP address. ";
         throw;   // forward exception to next handler
     }
     boost::net::dns::resolve resolver;
index 4021004..ef11eac 100644 (file)
@@ -409,7 +409,7 @@ istream& MessagePayload::read( istream &is )
     size_t data_received_in_bytes = static_cast<size_t>( is.gcount() );
     if ( data_received_in_bytes != PayloadSizeInBytes )
     {
-        GlobalLogger.error() << "Error: expecting " << PayloadSizeInBytes
+        GlobalLogger.error() << "Expecting " << PayloadSizeInBytes
                 << " bytes, but received " << is.gcount() << " bytes." << endl;
     }
 
index 8f40122..364376c 100644 (file)
@@ -118,7 +118,7 @@ bool NetworkInterface<SocketType, Protocol>::bind()
     if ( ret == -1 )
     {
         I2n::Logger::GlobalLogger.error()
-            << "Error: could not bind pinger to interface " << Name << std::endl;
+            << "Could not bind pinger to interface " << Name << std::endl;
         return false;
     }
 
index 8e30fcd..823f3ce 100644 (file)
@@ -55,7 +55,7 @@ NetworkInterfaceList::~NetworkInterfaceList()
     }
     catch ( ... )
     {
-        GlobalLogger.error() << "Error: could not destroy network interface list."
+        GlobalLogger.error() << "Could not destroy network interface list."
                 << endl;                                                                       //lint !e1551
     }
 } //lint !e1579
index 7df5039..57d0b44 100644 (file)
@@ -27,6 +27,8 @@
 #include <boost/asio/ip/tcp_raw_protocol.hpp>
 #include <boost/system/system_error.hpp>
 
+#include <logfunc.hpp>
+
 #include "boost_assert_handler.h"
 #include "icmp/icmppinger.h"
 #include "tcp/tcppinger.h"
@@ -36,6 +38,7 @@ using boost::shared_ptr;
 using boost::asio::ip::icmp;
 using boost::asio::ip::tcp_raw_protocol;
 using boost::system::system_error;
+using I2n::Logger::GlobalLogger;
 
 //-----------------------------------------------------------------------------
 // PingerFactory
@@ -103,7 +106,7 @@ PingerItem PingerFactory::createPinger(
     {
         // Raw sockets are locked down by Unix operating systems to prevent
         // malware and security holes, thus it requires root access to use it.
-        cerr << "Error: pingcheck must run as root (" << ex.what() << ")" << endl;
+        GlobalLogger.error() << "Pingcheck must run as root (" << ex.what() << ")" << endl;
         exit( EXIT_FAILURE );
     }
 
index e7b9e3e..b11cbf1 100644 (file)
@@ -148,7 +148,7 @@ void PingScheduler::resolve_and_ping()
     // determine if address resolution is required
     if ( !ips_up_to_date )
     {
-        ips_up_to_date = Ping->resolve_ping_address();    // try to resolve 
+        ips_up_to_date = Ping->resolve_ping_address();    // try to resolve
         if ( ips_up_to_date )
         {
             EverHadAnyIP = true;
index 6fe8f8c..c9042bd 100644 (file)
@@ -77,8 +77,6 @@ IcmpPacketItem IcmpPacketFactory::create_icmp_packet(
             << IcmpPacket::return_code_to_string(return_code) << endl;
         icmp_packet.reset();    // --> (!icmp_packet) is true
            // --> icmp_pinger will not try to continue working with this packet
-
-        // TODO why good packets are reports as bad? The read() has problems!
     }
     else if ( !is.good() )
     {
index 20433dc..4918aa5 100644 (file)
@@ -248,7 +248,7 @@ IcmpPacket::ReadReturnCode Icmpv4Packet::read( istream &is )
     // try to read that amount of data
     if ( data_length < 0 )
     {
-        GlobalLogger.error() << "Error: invalid size for optional ICMP data: "
+        GlobalLogger.error() << "Invalid size for optional ICMP data: "
                              << data_length << endl;
         is.setstate( ios::failbit );
         return IcmpPacket::ReadReturnCode_INVALID_SIZE;
index 5545add..38910cb 100644 (file)
@@ -263,7 +263,7 @@ IcmpPacket::ReadReturnCode Icmpv6Packet::read( istream &is )
     // try to read that amount of data
     if ( data_length < 0 )
     {
-        GlobalLogger.error() << "Error: invalid size for optional ICMP data: "
+        GlobalLogger.error() << "Invalid size for optional ICMP data: "
                              << data_length << endl;
         is.setstate( ios::failbit );
         return IcmpPacket::ReadReturnCode_INVALID_SIZE;
index 1235f7b..821f0e7 100644 (file)
@@ -220,7 +220,7 @@ istream &operator>>(
     uint8_t header_version = header.get_version();
     if ( header_version != 4 )
     {
-        GlobalLogger.error() << "Error: invalid IP header version: " << static_cast<int>(header_version) << endl;
+        GlobalLogger.error() << "Invalid IP header version: " << static_cast<int>(header_version) << endl;
 
         is.setstate( ios::failbit );
         return is;
@@ -232,7 +232,7 @@ istream &operator>>(
                                 static_cast<streamsize>( Ipv4HeaderSizeInBytes );
     if ( ( options_length < 0 ) || ( 40 < options_length ) )
     {
-        GlobalLogger.error() << "Error: invalid IP options length value:" << options_length << endl;
+        GlobalLogger.error() << "Invalid IP options length value:" << options_length << endl;
         is.setstate( ios::failbit );
     }
     else if ( ( 0 < options_length ) && ( options_length <= 40 ) )
index 09881b9..2e2d9e3 100644 (file)
@@ -65,7 +65,7 @@ LinkStatusItem get_status_notifier(const ConfigurationItem&);
 void init_logger();
 void set_log_output(const ConfigurationItem &);
 DelayMap calc_pinger_delays(const HostList &hosts);
-void init_pingers(const IoServiceItem, const ConfigurationItem&, 
+void init_pingers(const IoServiceItem, const ConfigurationItem&,
                   const LinkStatusItem&, PingSchedulerList*);
 void start_pingers(const PingSchedulerList&);
 void stop_pingers(const PingSchedulerList&);
@@ -141,12 +141,11 @@ LinkStatusItem get_status_notifier(
 
 void init_logger()
 {
-    // set default: log at level NOTICE to syslog
-    const int default_log_level = I2n::Logger::LogLevel::Notice;
-
+    // set default: log at level NOTICE to syslog and stderr
+    //   to ensure that in case of faulty config, the error is noticed
     I2n::Logger::enable_syslog( I2n::Logger::Facility::User );
     I2n::Logger::enable_stderr_log( true );
-    I2n::Logger::set_log_level( default_log_level );
+    I2n::Logger::set_log_level( I2n::Logger::LogLevel::Notice );
 }
 
 void set_log_output(
@@ -182,7 +181,7 @@ void set_log_output(
  *
  * If there are many pingers with same interval, will get bursts of pings
  * and none in-between. This function calculates delays for large numbers
- * of hosts with same ping intervals, to distribute them as evenly as 
+ * of hosts with same ping intervals, to distribute them as evenly as
  * possible, right from the start (might diverge over time, anyway).
  *
  * Will not do much good for pingers with many different intervals, but
@@ -303,12 +302,25 @@ void stop_pingers(
 // the one instance of signal_data_struct
 signal_data_struct signal_data;
 
+
+/// registered as signal handler; mainly sets signal_data.signaled_flag
 void signal_handler(int param)
 {
-    GlobalLogger.info() << "signal handler called with param " << param << endl;
+    if (param == SIGUSR1)
+        GlobalLogger.debug() << "signal handler called with SIGUSR1." << endl;
+    else if (param == SIGUSR2)
+        GlobalLogger.debug() << "signal handler called with SIGUSR2." << endl;
+    else if (param == SIGTERM)
+        GlobalLogger.debug() << "signal handler called with SIGTERM." << endl;
+    else if (param == SIGINT)
+        GlobalLogger.debug() << "signal handler called with SIGINT." << endl;
+    else
+        GlobalLogger.warning() << "signal handler called with unexpected signal " << param << endl;
     signal_data.signaled_flag = param;
 }
 
+
+/// called regularly from io_service; checks signal_data.signal_flag
 void signal_checker( const boost::system::error_code &error )
 {
     bool want_stop = false;
@@ -322,7 +334,8 @@ void signal_checker( const boost::system::error_code &error )
         }
         else
         {
-            GlobalLogger.error() << "not implemented yet! Stopping io_service" << endl;
+            GlobalLogger.error() << "Signal check timer handler received error code " << error
+                << "! Stopping io_service" << endl;
             want_stop = true;
         }
     }
@@ -337,18 +350,18 @@ void signal_checker( const boost::system::error_code &error )
         {
             int new_log_level = I2n::Logger::get_log_level()+1;
             I2n::Logger::set_log_level( new_log_level );
-            GlobalLogger.info() << "Increased log level to "
+            GlobalLogger.debug() << "Increased log level to "
                 << I2n::Logger::get_log_level_string();
         }
         else if ( signaled_flag == SIGUSR2 )
         {
             I2n::Logger::set_log_level( signal_data.config_log_level );
-            GlobalLogger.info() << "Reset log level to normal ("
+            GlobalLogger.debug() << "Reset log level to normal ("
                 << I2n::Logger::get_log_level_string() << ")";
         }
         else if ( ( signaled_flag == SIGTERM ) || ( signaled_flag == SIGINT ))
         {
-            GlobalLogger.info() << "Received signal SIGINT/SIGTERM --> will stop" << endl;
+            GlobalLogger.debug() << "Received signal SIGINT/SIGTERM --> will stop" << endl;
             want_stop = true;
         }
     }
index fa99849..22ddf1a 100644 (file)
@@ -87,7 +87,7 @@ TcpPinger::TcpPinger(
 {
     if ( !NetInterface.bind() )
     {
-        GlobalLogger.error() << "Error: could not bind the socket with the local interface. "
+        GlobalLogger.error() << "Could not bind the socket with the local interface. "
                 << ::strerror( errno )  << endl;
     }
 
@@ -192,7 +192,7 @@ void TcpPinger::send_ack_request( const TcpSegmentItem tcp_segment )
     ostream os( &request_buffer );
     if ( !tcp_segment->write( os ) )
     {
-        GlobalLogger.error() << "Error: fail writing ping data." << endl;
+        GlobalLogger.error() << "Fail writing ping data." << endl;
     }
 
     TimeSent = microsec_clock::universal_time();
@@ -209,13 +209,13 @@ void TcpPinger::send_ack_request( const TcpSegmentItem tcp_segment )
         size_t bytes_sent = Socket.send_to( data, DestinationEndpoint );
         if ( bytes_sent != buffer_size( data ) )
         {
-            GlobalLogger.error() << "Error: fail sending ping data."
+            GlobalLogger.error() << "Fail sending ping data."
                     << "Amount of bytes sent differs from the buffer." << endl;
         }
     }
     catch ( const exception &ex )
     {
-        GlobalLogger.error() << "Error: fail sending ping data. " << ex.what() << endl;
+        GlobalLogger.error() << "Fail sending ping data. " << ex.what() << endl;
     }
 
     // Tell how long to wait for the reply
@@ -278,7 +278,7 @@ void TcpPinger::handle_receive_tcp_segment( const size_t &bytes_transferred )
         istream is( &ReplyBuffer );
         if ( !is )
         {
-            GlobalLogger.error() << "Error: can't handle ReplyBuffer" << endl;
+            GlobalLogger.error() << "Can't handle ReplyBuffer" << endl;
             return;
         }
 
@@ -319,7 +319,7 @@ void TcpPinger::handle_receive_tcp_segment( const size_t &bytes_transferred )
     }
     catch ( ... )
     {
-        GlobalLogger.notice() << "Warning: exception during ICMP parse. "
+        GlobalLogger.notice() << "Exception during ICMP parse. "
             << "Starting another receive till timeout." << endl;
         start_receive();
     }
index 5d6bcde..226725a 100644 (file)
@@ -70,7 +70,7 @@ TcpSegmentItem TcpSegmentFactory::create_tcp_segment(
 
     if ( !tcp_segment->read( is ) )
     {
-        GlobalLogger.error() << "Error: could not read TCP Segment." << endl;
+        GlobalLogger.error() << "Could not read TCP Segment." << endl;
     }
 
     return tcp_segment;