ensured LogPrefix is used in DNS and PingScheduler; shortened lines; remove vim end...
authorChristian Herdtweck <christian.herdtweck@intra2net.com>
Wed, 29 Apr 2015 13:36:04 +0000 (15:36 +0200)
committerChristian Herdtweck <christian.herdtweck@intra2net.com>
Mon, 4 May 2015 14:57:58 +0000 (16:57 +0200)
src/dns/dnscache.cpp
src/dns/dnsmaster.cpp
src/dns/dnsresolver.cpp
src/host/pingscheduler.cpp

index 4ad62c4..3a507e6 100644 (file)
@@ -149,7 +149,7 @@ void DnsCache::save_to_cachefile()
         }
         catch (std::exception &exc)
         {
-            GlobalLogger.warning() << "Saving failed: " << exc.what();
+            GlobalLogger.warning() << "DnsCache: Saving failed: " << exc.what();
         }
     }
 }
@@ -399,6 +399,3 @@ std::string DnsCache::get_first_outdated_cname(const std::string &hostname,
     // --> all are up-to-date
     return "";
 }
-
-// (created using vim -- the world's best text editor)
-
index 9592e1c..f25f09c 100644 (file)
@@ -42,7 +42,7 @@ void DnsMaster::create_master(const IoServiceItem &io_serv,
                             const int max_address_resolution_attempts,
                             const std::string &cache_file)
 {
-    GlobalLogger.info() << "Creating DNS Cache";
+    GlobalLogger.info() << "DnsMaster: Creating cache";
     DnsCacheItem cache( new DnsCache(io_serv, cache_file) );
     create_master(io_serv, default_name_server, resolved_ip_ttl_threshold,
                   max_address_resolution_attempts, cache);
@@ -56,12 +56,12 @@ void DnsMaster::create_master(const IoServiceItem &io_serv,
 {
     if (TheOnlyInstance)
     {
-        GlobalLogger.warning()
-            << "Blocking attempt to create another DnsMaster instance!";
+        GlobalLogger.warning() << "DnsMaster: "
+                              << "Blocking attempt to create another instance!";
         return;
     }
 
-    GlobalLogger.info() << "Creating DNS Master";
+    GlobalLogger.info() << "DNS Master: creating instance";
     TheOnlyInstance.reset( new DnsMaster(io_serv,
                                          default_name_server,
                                          resolved_ip_ttl_threshold,
@@ -88,19 +88,19 @@ DnsMaster::DnsMaster(const IoServiceItem &io_serv,
 DnsMasterItem& DnsMaster::get_instance()
 {
     if ( !TheOnlyInstance )
-        GlobalLogger.error()
-            << "Request to return DnsMaster instance before creating it!";
+        GlobalLogger.error() << "DnsMaster: "
+                            << "Request to return instance before creating it!";
     return TheOnlyInstance;
 }
 
 DnsMaster::~DnsMaster()
 {
-    GlobalLogger.info() << "DnsMaster is being destructed";
+    GlobalLogger.info() << "DnsMaster: being destructed";
 
     if (DnsMaster::TheOnlyInstance)
     {   // apparently, this static variable still exists while itself is
         // destructed...
-        //GlobalLogger.warning() << "DnsMaster is being destructed that is not "
+        //GlobalLogger.warning() << "DnsMaster: being destructed but not "
         //                       << "singleton instance TheOnlyInstance!";
         DnsMaster::TheOnlyInstance.reset();
     }
@@ -135,10 +135,12 @@ ResolverItem& DnsMaster::get_resolver_for(const std::string &hostname,
                               = boost::asio::ip::address::from_string(hostname);
             if ( (protocol == DNS_IPv4 && !ip.is_v4()) ||
                  (protocol == DNS_IPv6 && !ip.is_v6()) )
-                GlobalLogger.warning() << "Asked to create a DNS resolver "
+                GlobalLogger.warning() << "DnsMaster:"
+                                       << "Asked to create a DNS resolver "
                                        << "for wrong IP protocol: v4 != v6! "
                                        << "We will comply.";
-            GlobalLogger.info() << "Creating PseudoResolver for IP " << ip;
+            GlobalLogger.info() << "DnsMaster: Creating PseudoResolver for IP "
+                                << ip;
             ResolverItem new_resolver( new IpPseudoResolver(IoService,
                                                             hostname,
                                                             Cache) );
@@ -188,7 +190,7 @@ DnsIpProtocol DnsMaster::ping2dns_protocol(const PingProtocol& pprot)
         case PingProtocol_TCP:      return DNS_IPv4; break;
         case PingProtocol_TCP_IPv6: return DNS_IPv6; break;
         default:
-            GlobalLogger.warning() << "Unexpected ping protocol: "
+            GlobalLogger.warning() << "DnsMaster: Unexpected ping protocol: "
                                    << static_cast<int>(pprot);
             return DNS_IPALL;
             break;
@@ -221,5 +223,3 @@ std::string to_string(const DnsIpProtocol &protocol)
                  return "Unexpected Protocol"; break;
     }
 }
-// (created using vim -- the world's best text editor)
-
index a1c81ad..0ac9828 100644 (file)
@@ -226,7 +226,7 @@ void DnsResolver::handle_dns_result(const boost::system::error_code &error,
     std::vector<src_cname_pair> result_cnames;
     std::vector<string_pair> result_name_servers;
 
-    GlobalLogger.debug() << "Checking ANSWERS section of dns reply";
+    GlobalLogger.debug() << LogPrefix <<"Checking ANSWERS section of dns reply";
     gather_results(result_message.answers(), &result_ips, &result_cnames,
                                                           &result_name_servers);
     // results should have the logical order
@@ -729,5 +729,3 @@ int DnsResolver::get_resolved_ip_count()
     return ResolverBase::get_cached_ips_recursively("", true).size();
 }
 
-// (created using vim -- the world's best text editor)
-
index e2267fd..0f08565 100644 (file)
@@ -51,7 +51,7 @@ using I2n::Logger::GlobalLogger;
  * @brief Parameterized constructor.
  *
  * @param io_serv The one @c io_serv object that controls async processing
- * @param network_interface The name of the network interface originating the pings.
+ * @param network_interface The name of the network interface sending the pings.
  * @param destination_address The remote address to ping.
  * @param destination_port The remote port to ping.
  * @param ping_protocol_list A list of protocols to use.
@@ -84,7 +84,8 @@ PingScheduler::PingScheduler(
     NextPingTimer( *io_serv ),
     TimeSentLastPing( microsec_clock::universal_time() ),
     PingReplyTimeout( ping_reply_timeout ),
-    HostAnalyzer( destination_address, ping_fail_percentage_limit, link_analyzer ),
+    HostAnalyzer( destination_address, ping_fail_percentage_limit,
+                  link_analyzer ),
     Resolver(),
     Ping(),
     WantToPing( false ),
@@ -113,13 +114,13 @@ PingScheduler::~PingScheduler()
 
 void PingScheduler::stop_pinging()
 {
-    // stop pinger, which will probably call ping_done_handler --> re-new NextPingTimer
-    GlobalLogger.debug() << "scheduler: stop pinging" << endl;
+    // stop pinger and resolver
+    GlobalLogger.debug() << LogPrefix << "scheduler: stop pinging";
     Ping->stop_pinging();
     Resolver->cancel_resolve();
 
-    // now cancel the own timer
-    GlobalLogger.debug() << "scheduler: cancel timer" << endl;
+    // now cancel the own timer in case that pinger cancelation called callback
+    GlobalLogger.debug() << LogPrefix << "scheduler: cancel timer";
     NextPingTimer.cancel();
 }
 
@@ -132,9 +133,10 @@ void PingScheduler::stop_pinging()
 void PingScheduler::start_pinging()
 {
     if ( FirstDelay > 0 )
-        GlobalLogger.info() << "Delaying first ping by " << FirstDelay << "s";
+        GlobalLogger.info() << LogPrefix << "Delaying first ping by "
+                                         << FirstDelay << "s";
     else
-        GlobalLogger.info() << "Schedule ping as soon as possible";
+        GlobalLogger.info() << LogPrefix << "Schedule ping as soon as possible";
 
     (void) NextPingTimer.expires_from_now( seconds( FirstDelay ) );
     NextPingTimer.async_wait( bind( &PingScheduler::ping, this,
@@ -150,12 +152,11 @@ void PingScheduler::ping(const boost::system::error_code &error)
     if ( error )
     {   // get here, e.g. by NextPingTimer.cancel in stop_pinging
         if ( error ==  boost::asio::error::operation_aborted )
-            GlobalLogger.error() << "Timer for ping was cancelled! "
-                                 << "Stopping" << endl;
+            GlobalLogger.error() << LogPrefix << "Timer for ping was cancelled!"
+                                 << " --> Stopping";
         else
-            GlobalLogger.error() << "Received error " << error
-                                 << " waiting for ping! Stopping"
-                                 << endl;
+            GlobalLogger.error() << LogPrefix << "Received error " << error
+                                 << " waiting for ping! Stopping";
         return;
     }
 
@@ -169,19 +170,19 @@ void PingScheduler::ping_when_ready()
 {
     if ( !WantToPing )
     {
-        GlobalLogger.info() << "PingScheduler: not pinging (not requested to)";
+        GlobalLogger.info() << LogPrefix << "not pinging (not requested to)";
         return;
     }
     else if ( Resolver && Resolver->is_resolving() )
     {
-        GlobalLogger.info() << "PingScheduler: not pinging (DNS not finished)";
+        GlobalLogger.info() << LogPrefix << "not pinging (DNS not finished)";
         return;
     }
     else if ( !Resolver )
         // should not happen, but check anyway
         GlobalLogger.warning() << LogPrefix << "Have no resolver!";
 
-    GlobalLogger.info() << "PingScheduler: start ping";
+    GlobalLogger.info() << LogPrefix << "start ping";
     WantToPing = false;
 
     // try to get an up-to-date IP
@@ -249,15 +250,15 @@ void PingScheduler::update_ping_interval()
     {
         PingIntervalInSec.speed_up();
 
-        GlobalLogger.debug() << "- Speeding up ping interval to: " << PingIntervalInSec << "s"
-                << endl;
+        GlobalLogger.debug() << LogPrefix << "- Speeding up ping interval to: "
+                             << PingIntervalInSec << "s";
     }
     else
     {
         PingIntervalInSec.back_to_original();
 
-        GlobalLogger.debug() << "- Stick to the original ping interval: " << PingIntervalInSec << "s"
-                << endl;
+        GlobalLogger.debug() << LogPrefix << "- Stick to the original ping "
+                             << "interval: " << PingIntervalInSec << "s";
     }
 }
 
@@ -266,7 +267,8 @@ void PingScheduler::update_ping_elapsed_time()
     ptime now = microsec_clock::universal_time();
     time_resolution_traits_adapted64_impl::int_type elapsed_time_in_sec =
             (now - TimeSentLastPing).total_seconds();
-    GlobalLogger.debug() << "- Time elapsed since last ping: " << elapsed_time_in_sec << "s" << endl;
+    GlobalLogger.debug() << LogPrefix << "- Time elapsed since last ping: "
+                                      << elapsed_time_in_sec << "s";
 
     TimeSentLastPing = microsec_clock::universal_time();
 }
@@ -310,8 +312,9 @@ void PingScheduler::get_next_ping_protocol()
 
 bool PingScheduler::can_change_ping_protocol() const
 {
-    // TODO can_change_ping_protocol() and get_next_ping_protocol() may be implemented in a Algorithm
-    // class that can be exchanged in this class to provide an algorithm neutral class
+    // TODO can_change_ping_protocol() and get_next_ping_protocol() may be
+    // implemented in a Algorithm class that can be exchanged in this class to
+    // provide an algorithm neutral class
     return true;
 }
 
@@ -334,8 +337,8 @@ void PingScheduler::update_dns_resolver( PingProtocol current_protocol )
 {
     if (Resolver && Resolver->is_resolving())
     {
-        GlobalLogger.warning() << "Resolver still seems to be resolving "
-                               << "--> cancel!";
+        GlobalLogger.warning() << LogPrefix
+                          << "Resolver still seems to be resolving --> cancel!";
         Resolver->cancel_resolve();
     }
 
@@ -348,7 +351,7 @@ void PingScheduler::update_dns_resolver( PingProtocol current_protocol )
     if ( Resolver->have_up_to_date_ip() )
     {
         if (!Resolver->is_resolving())
-            GlobalLogger.warning() << "PingScheduler: have up to date IPs but "
+            GlobalLogger.warning() << LogPrefix << "have up to date IPs but "
                 << "resolver seems to be resolving all the same... "
                 << "Start pinging anyway!";
         ping_when_ready();
@@ -366,7 +369,7 @@ void PingScheduler::start_resolving_ping_address()
 void PingScheduler::dns_resolve_callback(const bool was_success,
                                          const int cname_count)
 {
-    GlobalLogger.info() << "PingScheduler: dns resolution finished "
+    GlobalLogger.info() << LogPrefix << "dns resolution finished "
                         << "with success = " << was_success << " "
                         << "and cname_count = " << cname_count;