2 * @brief Logger class implementation. This class implements the Logging facility.
6 * @copyright Intra2net AG
17 #include <boost/foreach.hpp>
23 namespace po = boost::program_options;
25 typedef boost::shared_ptr<boost::program_options::options_description> Options_descriptionPtr;
35 , ExternalWarningLevel(0)
36 , ExternalLogOnlyOnce(false)
38 set_log_facility(Loglevel,Syslog,ExternalWarningLog,ExternalWarningLevel,ExternalLogOnlyOnce);
51 * Decides if a external log message can be send.
52 * @param msg The message to log.
54 bool Logger::is_allowed_to_send( const string& msg ) const
56 if ( (ExternalLogOnlyOnce) && (ExternalSendMessages.find(msg) != ExternalSendMessages.end()) )
63 * Clears the external send messages set.
65 void Logger::clear_external_send_messages()
67 ExternalSendMessages.clear();
72 * Decides if Logging through syslog if enabled or through std.
73 * @param msg The message to log.
75 void Logger::log_notice(const string& msg) const
78 syslog(LOG_NOTICE,msg.c_str());
85 * Decides if Logging through syslog if enabled or through std.
86 * @param msg The message to log.
88 void Logger::log_warning(const string& msg, int level)
91 syslog(LOG_WARNING,msg.c_str());
95 if ( (level <= ExternalWarningLevel) && (!ExternalWarningLog.empty()) && (is_allowed_to_send(msg)) )
98 // Remove endline from msg.
99 if (!message.empty() && message[message.length()-1] == '\n')
100 message.erase(message.length()-1); /*lint !e534 */
102 string external = ExternalWarningLog;
103 external.append(" ");
104 external.append("\"");
105 external.append(message);
106 external.append("\"");
107 if ( system(external.c_str()) != 0 )
108 print_error_external_logging(external);
110 ExternalSendMessages.insert(msg); /*lint !e534 */
116 * Decides if Logging through syslog if enabled or through std.
117 * @param msg The message to log.
119 void Logger::log_error(const string& msg) const
122 syslog(LOG_ERR,msg.c_str());
129 * Setter for member Loglevel.
130 * @param _loglevel Value to set Loglevel to.
132 void Logger::set_external_log_only_once( const bool _external_log_only_once )
134 ExternalLogOnlyOnce = _external_log_only_once;
139 * Setter for member Loglevel.
140 * @param _loglevel Value to set Loglevel to.
142 void Logger::set_loglevel(const int _loglevel)
144 Loglevel = _loglevel;
149 * Getter for member Loglevel.
152 int Logger::get_loglevel() const
159 * Setter for member Syslog.
160 * @param _syslog Wether to log through syslog or not.
162 void Logger::set_syslog(const bool _syslog)
169 * Getter for member Syslog.
170 * @return True if logging through syslog is enabled, false otherwise.
172 bool Logger::get_syslog() const
179 * Initialize the logging facility.
181 void Logger::set_log_facility(const int _loglevel, const bool _syslog, const string& _external_error_log, const int _external_error_level, const bool _external_log_only_once )
183 Loglevel = _loglevel;
185 ExternalWarningLog = _external_error_log;
186 ExternalWarningLevel = _external_error_level;
187 ExternalLogOnlyOnce = _external_log_only_once;
190 openlog("bpdyndnsd",LOG_PID,LOG_DAEMON);
195 * Prints out the usage to the command line.
197 void Logger::print_usage(const Options_descriptionPtr opt_desc) const
200 if ( level <= Loglevel )
203 msg << "Usage: bpdyndnsd [Command line options]" << "\n" << endl;
204 msg << *opt_desc << endl;
205 log_notice(msg.str());
211 * Prints out the programm name and the given version string on stdout.
212 * @param version Version string.
214 void Logger::print_version() const
217 if ( level <= Loglevel )
220 msg << "Bullet proof dynamic dns daemon.\nbpdyndnsd " << VERSION << "." << REVISION << "." << RELEASE << endl;
221 log_notice(msg.str());
227 * Prints out the successful parsing of the command line options.
229 void Logger::print_cmd_parsed() const
232 if ( level <= Loglevel )
234 log_notice("Command line options successfully parsed.");
239 void Logger::print_conf_files_parsed() const
242 if ( level <= Loglevel )
244 log_notice("Config files successfully parsed.");
250 * Prints out the successful parsing of the config files.
251 * @param config_path The specified config path.
253 void Logger::print_conf_loaded(const string& config_path) const
256 if ( level <= Loglevel )
259 msg << "Config files successfully loaded in: " << config_path << endl;
260 log_notice(msg.str());
266 * Prints out the unsuccessful parsing of the config files.
267 * @param config_path The specified config path.
269 void Logger::print_conf_not_loaded(const string& config_path) const
272 if ( level <= Loglevel )
275 msg << "Config files couldn't be loaded in: " << config_path << endl;
276 log_error(msg.str());
282 * A file could not be opened for reading.
283 * @param filename The filename.
285 void Logger::print_error_opening_r(const string& filename) const
288 if ( level <= Loglevel )
291 msg << "Error opening file for reading: " << filename << endl;
292 log_error(msg.str());
298 * A file could not be opened for writing.
299 * @param filename The filename.
301 void Logger::print_error_opening_rw(const string& filename) const
304 if ( level <= Loglevel )
307 msg << "Error opening file for writing: " << filename << endl;
308 log_error(msg.str());
314 * Desctructor of specified class was called.
315 * @param _class Name of the class.
317 void Logger::print_destructor_call(const string& _class) const
320 if ( level <= Loglevel )
323 msg << "Destructor call: " << _class << endl;
324 log_notice(msg.str());
330 * Constructor of specified class was called.
331 * @param _class Name of the class.
333 void Logger::print_constructor_call(const string& _class) const
336 if ( level <= Loglevel )
339 msg << "Constructor call: " << _class << endl;
340 log_notice(msg.str());
346 * Update method for specified service was called.
347 * @param service The service for which is the update running.
349 void Logger::print_update_service(const string& service) const
352 if ( level <= Loglevel )
355 msg << "Running update for service: " << service << endl;
356 log_notice(msg.str());
362 * An unknown option on the command line was detected.
363 * @param unknown_option The unknown option.
365 void Logger::print_unknown_cmd_option(const string& unknown_option) const
368 if ( level <= Loglevel )
371 msg << "Unknown option on command line detected: " << unknown_option << endl;
372 log_error(msg.str());
378 * An unknown protocol was specified.
379 * @param protocol The unknown protocol.
381 void Logger::print_unknown_protocol(const string& protocol) const
384 if ( level <= Loglevel )
387 msg << "Unknown protocol defined: " << protocol << endl;
388 log_error(msg.str());
394 * Loading a service config file.
395 * @param filename The service config file.
397 void Logger::print_load_service_conf(const string& filename) const
400 if ( level <= Loglevel )
403 msg << "Loading service config file: " << filename << endl;
404 log_notice(msg.str());
410 * Loading the main config file.
411 * @param filename The main config file.
413 void Logger::print_load_main_conf(const string& filename) const
416 if ( level <= Loglevel )
419 msg << "Loading main config file: " << filename << endl;
420 log_notice(msg.str());
426 * There is an unknown option in a service config file.
427 * @param unknown_option The unknown option.
429 void Logger::print_unknown_service_conf_option(const string& service_conf_file, const string& unknown_option) const
432 if ( level <= Loglevel )
435 msg << "Unknown option in service config file detected: " << service_conf_file << " Unknown option: " << unknown_option << endl;
436 log_error(msg.str());
442 * There is an unknown option in the main config file.
443 * @param unknown_option The unknown option.
445 void Logger::print_unknown_main_conf_option(const string& unknown_option) const
448 if ( level <= Loglevel )
451 msg << "Unknown option in main config file detected: " << unknown_option << endl;
452 log_error(msg.str());
458 * The defined config path doesn't exist or is not a directory.
459 * @param config_path The defined config path.
461 void Logger::print_error_config_path(const string& config_path) const
464 if ( level <= Loglevel )
467 msg << "Config path doesn't exists or is not a diretory: " << config_path << endl;
468 log_error(msg.str());
474 * There is a missing command line option to initialize a service object.
476 void Logger::print_missing_cmd_service_option() const
479 if ( level <= Loglevel )
481 log_error("Missing option to initialize service. Protocol, host, login and password must be specified.");
487 * Missing option in service config file.
488 * @param service_conf_file Service config file
490 void Logger::print_missing_service_conf_option(const string& service_conf_file) const
493 if ( level <= Loglevel )
496 msg << "Missing option in service config file " << service_conf_file << " to initialize service. Protocol, host, login and password must be specified." << endl;
497 log_error(msg.str());
503 * Process running as daemon.
504 * @param pid The pid of the daemon.
506 void Logger::print_runnig_as_daemon(const int pid) const
509 if ( level <= Loglevel )
512 msg << "Runnig as daemon: " << pid << endl;
513 log_notice(msg.str());
519 * Prints out the daemon mode.
520 * @param daemon_mode The daemon mode.
522 void Logger::print_daemon_mode(const bool daemon_mode) const
525 if ( level <= Loglevel )
527 string mode = "disabled";
528 if (daemon_mode == true)
531 msg << "Daemon mode is " << mode << "." << endl;
532 log_notice(msg.str());
538 * There was an error while trying to fork.
540 void Logger::print_error_fork() const
543 if ( level <= Loglevel )
545 log_error("Error while trying to fork.");
551 * A pid in the pidfile was found.
552 * @param pid The pid found in the pidfile.
554 void Logger::print_pid_found(const int pid) const
557 if ( level <= Loglevel )
560 msg << "Pidfile found: " << pid << ". Checking if process is still runnig..." << endl;
561 log_notice(msg.str());
567 * Another process is already running.
568 * @param pid The pid of the other process.
570 void Logger::print_process_already_running(const int pid) const
573 if ( level <= Loglevel )
576 msg << "Another bpdyndnsd process with PID " << pid << " is already running!" << endl;
577 log_error(msg.str());
585 void Logger::print_caught_sigterm() const
588 if ( level <= Loglevel )
590 log_notice("Caught SIGTERM. Exiting...");
598 void Logger::print_caught_siguser1() const
601 if ( level <= Loglevel )
603 log_notice("Caught SIGUSR1. Switching to offline mode...");
611 void Logger::print_caught_sighup() const
614 if ( level <= Loglevel )
616 log_notice("Caught SIGHUP. Reloading config...");
624 void Logger::print_caught_siguser2() const
627 if ( level <= Loglevel )
629 log_notice("Caught SIGUSR2. Switching to online mode...");
637 void Logger::print_caught_sigrtmin() const
640 if ( level <= Loglevel )
642 log_notice("Caught SIGRTMIN. Switching to online mode with webcheck enabled...");
648 * Error while setting signal handler.
650 void Logger::print_error_setting_signal(const string& signal) const
653 if ( level <= Loglevel )
656 msg << "Error while setting signal handler for: " << signal << endl;
657 log_error(msg.str());
663 * Error while setting signal handler.
665 void Logger::print_init_log_facility() const
668 if ( level <= Loglevel )
671 msg << "Initialized logging facility." << " Loglevel: " << Loglevel << " Syslog: " << Syslog << " ExternalLogOnlyOnce: " << ExternalLogOnlyOnce << endl;
672 log_notice(msg.str());
678 * Be verbose. Currently we are in offline mode.
680 void Logger::print_offline_mode() const
683 if ( level <= Loglevel )
685 log_notice("Offline mode...");
691 * Objects successfully serialized.
693 void Logger::print_serialized_objects_success() const
696 if ( level <= Loglevel )
698 log_notice("Serialized objects successfully.");
704 * Objects successfully de-serialized.
706 void Logger::print_deserialized_objects_success() const
709 if ( level <= Loglevel )
711 log_notice("De-serialized objects successfully.");
717 * Prints out the content of a service object.
718 * @param message Message to be added on output first.
719 * @param protocol Service's protocol.
720 * @param hostname Service's hostname.
721 * @param login Service's login.
722 * @param password Service's password.
723 * @param actual_ip Service's actual_ip.
724 * @param lastupdated Service's lastupdated.
726 void Logger::print_service_object(const string& message, const string& protocol, const string& hostname, const string& login, const string& password, const int update_interval, const int max_updates_within_interval, const int dns_cache_ttl , const string& actual_ip, list<time_t> lastupdated) const
729 if ( level <= Loglevel )
732 msg << message << endl;
733 msg << "\t" << "Protocol: " << protocol << endl;
734 msg << "\t" << "Hostname: " << hostname << endl;
735 msg << "\t" << "Login: " << login << endl;
736 msg << "\t" << "Password: " << password << endl;
737 msg << "\t" << "Update Interval: " << update_interval << endl;
738 msg << "\t" << "Max Updates: " << max_updates_within_interval << endl;
739 msg << "\t" << "DNS Cache TTL: " << dns_cache_ttl << endl;
740 msg << "\t" << "Actual_IP: " << actual_ip << endl;
741 BOOST_FOREACH( time_t update_time, lastupdated)
743 msg << "\t" << "Lastupdated: " << update_time << endl;
745 log_notice(msg.str());
751 * Caught exception while serialize.
752 * @param exception Exception message.
754 void Logger::print_exception_serialize(const string& errMsg) const
757 if ( level <= Loglevel )
760 msg << "Error while trying to serialize Serviceholder object: " << errMsg << endl;
761 log_error(msg.str());
767 * Caught exception while de-serialize.
768 * @param exception Exception message.
770 void Logger::print_exception_deserialize(const string& errMsg) const
773 if ( level <= Loglevel )
776 msg << "Error while trying to de-serialize Serviceholder object: " << errMsg << endl;
777 log_error(msg.str());
783 * Child couldn't be killed by parent.
784 * @param pid Pid of the child.
786 void Logger::print_error_kill_child(const int pid) const
789 if ( level <= Loglevel )
792 msg << "Could not kill child process with PID: " << pid << endl;
793 log_error(msg.str());
799 * Child was killed by parent because of error.
800 * @param pid The pid (child) killed.
802 void Logger::print_child_killed(const int pid) const
805 if ( level <= Loglevel )
808 msg << "Killed child process with PID: " << pid << endl;
809 log_notice(msg.str());
815 * There is no object file.
816 * @param object_file The object file.
818 void Logger::print_no_object_file(const string& object_file)
821 if ( (level <= Loglevel) || ((level <= ExternalWarningLevel) && (!ExternalWarningLog.empty())) )
824 msg << "There is no object file: " << object_file << ". Continue without recovering state from old services!" << endl;
825 log_warning(msg.str(),level);
831 * Prints out the given hostname
832 * @param hostname Hostname as string.
834 void Logger::print_hostname(const string& hostname) const
837 if ( level <= Loglevel )
840 msg << "Detected following hostname of localhost: " << hostname << endl;
841 log_notice(msg.str());
847 * Prints out the detected own ipv4 address
848 * @param ip_addr String representation of the detected ip.
850 void Logger::print_own_ipv4(const string& ip_addr_v4, const string& hostname) const
853 if ( level <= Loglevel )
856 msg << "Detected following IPv4-Address of host: " << hostname << " : " << ip_addr_v4 << endl;
857 log_notice(msg.str());
863 * Prints out the detected own ipv5 address
864 * @param ip_addr String representation of the detected ip.
866 void Logger::print_own_ipv6(const string& ip_addr_v6, const string& hostname) const
869 if ( level <= Loglevel )
872 msg << "Detected following IPv6-Address of host: " << hostname << " : " << ip_addr_v6 << endl;
873 log_notice(msg.str());
879 * Exception while trying to resolve hostname to ip.
880 * @param exception The exception caught.
881 * @param hostname The hostname.
883 void Logger::print_error_hostname_to_ip(const string& errMsg, const string& hostname) const
886 if ( level <= Loglevel )
889 msg << "Could not resolve the hostname: " << hostname << " to an IP-Address: " << errMsg << endl;
890 log_error(msg.str());
896 * The update of the given service was successful.
897 * @param service The service.
899 void Logger::print_update_service_successful(const string& service) const
902 if ( level <= Loglevel )
905 msg << "Updated service successful: " << service << endl;
906 log_notice(msg.str());
912 * No ip could be determined through webcheck
914 void Logger::print_webcheck_no_ip()
917 if ( (level <= Loglevel) || ((level <= ExternalWarningLevel) && (!ExternalWarningLog.empty())) )
919 log_warning("IP-Address of this host could not be determined through any configured webcheck url.",level);
925 * Connection problem while trying to get ip through webcheck url
926 * @param curl_err_buff Curl error message
929 void Logger::print_webcheck_url_connection_problem(const char * curl_err_buff, const string& url)
932 if ( (level <= Loglevel) || ((level <= ExternalWarningLevel) && (!ExternalWarningLog.empty())) )
935 msg << "There was a problem while trying to connect to following URL: " << url << " CURL error: " << curl_err_buff << endl;
936 log_warning(msg.str(),level);
942 * Prints out curl error.
943 * @param curl_err_buff Curl error message.
946 void Logger::print_webcheck_error(const char * curl_err_buff, const string& url) const
949 if ( level <= Loglevel )
952 msg << "There was an error while trying to connect to following URL: " << url << " CURL error: " << curl_err_buff << endl;
953 log_error(msg.str());
959 * Prints out the received data through curl.
960 * @param curl_data Data string
962 void Logger::print_received_curl_data(const string& curl_data) const
965 if ( level <= Loglevel )
968 msg << "Received CURL data: " << curl_data << endl;
969 log_notice(msg.str());
975 * IP was foudn through regex
976 * @param ip The IP found.
978 void Logger::print_regex_found_ip(const string& ip) const
981 if ( level <= Loglevel )
984 msg << "Found IP-Address via regex: " << ip << endl;
985 log_notice(msg.str());
991 * No IP was found through regex.
992 * @param data The data string which should contain a valid IP.s
994 void Logger::print_regex_ip_not_found(const string& data)
997 if ( (level <= Loglevel) || ((level <= ExternalWarningLevel) && (!ExternalWarningLog.empty())) )
1000 msg << "Could not extract an IP-Address via regex from following data:\n" << data << endl;
1001 log_warning(msg.str(),level);
1007 * Detected multiple occurrences of the same option.
1008 * @param message Error message.
1010 void Logger::print_multiple_cmd_option(const string& message) const
1013 if ( level <= Loglevel )
1016 msg << "The same option is only allowed once: " << message << endl;
1017 log_error(msg.str());
1023 * An update would exceed the update interval. Prints out a warning message.
1024 * @param current_time Current time.
1025 * @param old_time Time of update #MaxUpdatesWithinInterval ago.
1026 * @param MaxUpdatesWithinInterval Number of allowed updates in one update interval.
1027 * @param service The service which exceeds update interval.
1029 void Logger::print_update_not_allowed(const time_t current_time, const time_t old_time, const int MaxUpdatesWithinInterval, const string& service)
1032 if ( (level <= Loglevel) || ((level <= ExternalWarningLevel) && (!ExternalWarningLog.empty())) )
1035 msg << "Update not allowed for service: " << service << ". Too many updates within max update interval. Current time: " << current_time << ". Update time before " << MaxUpdatesWithinInterval << " updates: " << old_time << endl;
1036 log_warning(msg.str(),level);
1042 * Failure while running update for service.
1043 * @param service Services' name.
1045 void Logger::print_update_service_failure(const string& service)
1048 if ( (level <= Loglevel) || ((level <= ExternalWarningLevel) && (!ExternalWarningLog.empty())) )
1051 msg << "Could not update service: " << service << endl;
1052 log_warning(msg.str(),level);
1060 void Logger::print_starting_shutdown() const
1063 if ( level <= Loglevel )
1065 log_notice("Shutting down ...");
1073 void Logger::print_shutdown_succeeded() const
1076 if ( level <= Loglevel )
1078 log_notice("Shutting down complete ...");
1084 * Shutdown parent succeeded
1086 void Logger::print_shutdown_parent_succeeded() const
1089 if ( level <= Loglevel )
1091 log_notice("Shutting down parent process completed ...");
1097 * Starting shutdown parent
1099 void Logger::print_starting_shutdown_parent() const
1102 if ( level <= Loglevel )
1104 log_notice("Shutting down parent process ...");
1110 * DNS cache record timeout
1111 * @param hostname Hostname
1112 * @param lastupdated Lastupdated
1113 * @param dns_cache_ttl DNS cache TTL
1114 * @param current_time Current time
1116 void Logger::print_recheck_dns_entry(const string& hostname, const int lastupdated, const int dns_cache_ttl, const int current_time) const
1119 if ( level <= Loglevel )
1122 msg << "DNS cache record for host <" << hostname << "> expired or host will be updated for the first time: Lastupdated: " << lastupdated << " DNS cache ttl: " << dns_cache_ttl << " Current time: " << current_time << " Checking current DNS cache status." << endl;
1123 log_notice(msg.str());
1129 * Missing proxy option on command line.
1131 void Logger::print_missing_cmd_proxy_option() const
1134 if ( level <= Loglevel )
1136 log_error("Missing option to initialize proxy. http_proxy and http_proxy_port must be specified.");
1142 * Multiple option in service config file.
1143 * @param service_conf_file Service config file
1144 * @param message Multiple option text
1146 void Logger::print_multiple_service_conf_option(const string& service_conf_file, const string& message) const
1149 if ( level <= Loglevel )
1152 msg << "Multiple occurrences of the same option in service config file detected: " << service_conf_file << " " << message << endl;
1153 log_error(msg.str());
1159 * Multiple option in main config file.
1160 * @param service_conf_file Service config file
1161 * @param message Multiple option text
1163 void Logger::print_multiple_main_conf_option(const string& main_conf_file, const string& message) const
1166 if ( level <= Loglevel )
1169 msg << "Multiple occurrences of the same option in main config file detected: " << main_conf_file << " " << message << endl;
1170 log_error(msg.str());
1176 * Missing proxy option in main config file.
1177 * @param main_conf_filename The concerning config file.
1179 void Logger::print_missing_conf_proxy_option(const string& main_conf_filename) const
1182 if ( level <= Loglevel )
1185 msg << "Missing option to initialize proxy in main config file: " << main_conf_filename << " http_proxy and http_proxy_port must be specified." << endl;
1186 log_error(msg.str());
1192 * There is no domain part in the given hostname
1193 * @param hostname The hostname with no domain part in it.
1195 void Logger::print_no_domain_part(const string& hostname) const
1198 if ( level <= Loglevel )
1201 msg << "There is no domain part in the given hostname: " << hostname << endl;
1202 log_notice(msg.str());
1208 * Service is not initialized properly.
1209 * @param service The service.
1211 void Logger::print_httphelper_not_initialized() const
1214 if ( level <= Loglevel )
1216 log_error("HTTP-Helper is not initialized properly.");
1222 * An curl error occured.
1223 * @param msg The error message
1224 * @param curl_err_code The resulting curl error code
1226 void Logger::print_curl_error_init(const std::string& err_msg, const CURLcode curl_err_code) const
1228 string curl_err = "";
1230 if ( curl_err_code == CURLE_FAILED_INIT )
1231 curl_err = "CURLE_FAILED_INIT";
1233 curl_err = "UNKNOWN";
1236 if ( (level <= Loglevel) )
1239 msg << "Curl error: " << err_msg << " Curl error code: " << curl_err_code << " " << curl_err << endl; /*lint !e641 */
1240 log_error(msg.str());
1246 * An curl error occured.
1247 * @param url The url requested by the curl operation
1248 * @param curl_err_code The resulting curl error code
1250 void Logger::print_curl_error(const string& url, const CURLcode curl_err_code) const
1252 string curl_err = "";
1254 if ( curl_err_code == CURLE_URL_MALFORMAT )
1255 curl_err = "CURLE_URL_MALFORMAT";
1256 else if ( curl_err_code == CURLE_COULDNT_RESOLVE_HOST )
1257 curl_err = "CURLE_COULDNT_RESOLVE_HOST";
1258 else if ( curl_err_code == CURLE_COULDNT_CONNECT )
1259 curl_err = "CURLE_COULDNT_CONNECT";
1261 curl_err = "UNKNOWN";
1264 if ( (level <= Loglevel) )
1267 msg << "Curl error while requesting following url: " << url << " Curl error code: " << curl_err_code << " " << curl_err << endl; /*lint !e641 */
1268 log_error(msg.str());
1274 * An curl error occured.
1275 * @param url The url requested by the curl operation
1276 * @param curl_err_code The resulting curl error code
1277 * @param curl_err_buff The curl error buffer
1279 void Logger::print_curl_error(const string& url, const CURLcode curl_err_code, const char * curl_err_buff) const
1281 string curl_err = "";
1283 if ( curl_err_code == CURLE_URL_MALFORMAT )
1284 curl_err = "CURLE_URL_MALFORMAT";
1285 else if ( curl_err_code == CURLE_COULDNT_RESOLVE_HOST )
1286 curl_err = "CURLE_COULDNT_RESOLVE_HOST";
1287 else if ( curl_err_code == CURLE_COULDNT_CONNECT )
1288 curl_err = "CURLE_COULDNT_CONNECT";
1290 curl_err = "UNKNOWN";
1293 if ( (level <= Loglevel) )
1296 msg << "Curl error while requesting following url: " << url << " Curl error code: " << curl_err_code << " " << curl_err << " " << curl_err_buff << endl; /*lint !e641 */
1297 log_error(msg.str());
1303 * Prints out the data received by curl operation
1304 * @param CurlWritedataBuff
1306 void Logger::print_curl_data(const string& curl_writedata_buff) const
1309 if ( level <= Loglevel )
1312 msg << "Data received by curl: " << curl_writedata_buff << endl;
1313 log_notice(msg.str());
1319 * Not authorized to perform requested update operation
1320 * @param service The requested service.
1321 * @param username Username
1322 * @param password Password
1324 void Logger::print_service_not_authorized(const string& service, const string& username, const string& password) const
1327 if ( level <= Loglevel )
1330 msg << "Not authorized to perform update operation on service: " << service << " Please check username and password: " << username << ":" << password << endl;
1331 log_notice(msg.str());
1337 * Prints out the http status code
1339 * @param output HTTP status code
1341 void Logger::print_http_status_code(const string& url, const long http_code) const
1344 if ( level <= Loglevel )
1347 msg << "Requested URL: " << url << " Received HTTP status code: " << http_code << endl;
1348 log_notice(msg.str());
1354 * Generic failure while trying to update service
1355 * @param url The requested URL
1356 * @param curl_data The received curl_data from the server
1358 void Logger::print_update_failure(const string& url, const string& curl_data) const
1361 if ( (level <= Loglevel) )
1364 msg << "Problem while trying to updating service. Requested URL: " << url << " Error Code from Server: " << curl_data << endl;
1365 log_error(msg.str());
1371 * Generic failure while trying to update service
1372 * @param url The requested URL
1373 * @param http_status_code The received http status code
1375 void Logger::print_update_failure(const string& url, const long http_status_code) const
1378 if ( level <= Loglevel )
1381 msg << "Problem while trying to updating service. Requested URL: " << url << " Error Code from Server: " << http_status_code << endl;
1382 log_error(msg.str());
1387 * Hostname is invalid, contains no or only one domain part.
1388 * @param hostname The full qualified host name.
1390 void Logger::print_invalid_hostname(const string& hostname)
1393 if ( (level <= Loglevel) || ((level <= ExternalWarningLevel) && (!ExternalWarningLog.empty())) )
1396 msg << "The configured hostname: " << hostname << " is invalid. Please add the corresponding domain part." << endl;
1397 log_warning(msg.str(),level);
1403 * An IP in a private range was detected
1404 * @param ip The private IP
1406 void Logger::print_ip_is_local(const string& ip)
1409 if ( (level <= Loglevel) || ((level <= ExternalWarningLevel) && (!ExternalWarningLog.empty())) )
1412 msg << "The detected IP is within a private IP range: " << ip << endl;
1413 log_warning(msg.str(),level);
1419 * Regex is matching in string
1420 * @param regex The regex pattern
1421 * @param matching_string The string
1423 void Logger::print_regex_match(const string& regex, const string& matching_string) const
1426 if ( level <= Loglevel )
1429 msg << "Regex: " << regex << " is matching in: " << matching_string << endl;
1430 log_notice(msg.str());
1436 * Regex is not matching
1437 * @param regex Regex
1438 * @param not_matching_string String
1440 void Logger::print_no_regex_match(const string& regex, const string& not_matching_string)
1443 if ( (level <= Loglevel) || ((level <= ExternalWarningLevel) && (!ExternalWarningLog.empty())) )
1446 msg << "Regex: " << regex << " is not matching in: " << not_matching_string << endl;
1447 log_warning(msg.str(),level);
1453 * Could not parse gnudip initial reply.
1454 * @param curl_data The data received from gnudip server which should contain salt, time and sign.
1456 void Logger::print_could_not_parse_received_data(const string& curl_data) const
1459 if ( (level <= Loglevel) )
1462 msg << "Could not parse salt, time and sign from initial gnudip server reply: " << curl_data << endl;
1463 log_error(msg.str());
1469 * Gnudip salt, time and sign could not be got from map
1471 void Logger::print_could_not_get_initial_gnudip_data() const
1474 if ( (level <= Loglevel) )
1476 log_error("Could not get salt, time and sign from map.");
1483 * Gnudip protocol requires explicit declaration of a servername.
1485 void Logger::print_gnudip_requires_servername()
1488 if ( (level <= Loglevel) || ((level <= ExternalWarningLevel) && (!ExternalWarningLog.empty())) )
1490 log_warning("Gnudip requires explicit definition of servername via config!",level);
1496 * An exception occured while computing the md5 sum.
1497 * @param what The exception occured.
1499 void Logger::print_exception_md5_sum(const string& what) const
1502 if ( level <= Loglevel )
1505 msg << "An exception occured while computing a md5 sum: " << what << endl;
1506 log_error(msg.str());
1512 * An network exception occured.
1513 * @param what The exception occured.
1515 void Logger::print_network_error(const string& what) const
1518 if ( level <= Loglevel )
1521 msg << "An netowrk exception occured: " << what << endl;
1522 log_error(msg.str());
1528 * An undefined protocol error occured.
1529 * @param protocol The protocol
1530 * @param error The error
1532 void Logger::print_undefined_protocol_error(const string& protocol, const string& error) const
1535 if ( level <= Loglevel )
1538 msg << "An undefined protocol error occured. Protocol: " << protocol << " Error: " << error << endl;
1539 log_error(msg.str());
1544 * Error while trying to log through external program.
1545 * @param external_prog The external program called.
1547 void Logger::print_error_external_logging(const string& external_prog) const
1550 if ( level <= Loglevel )
1553 msg << "Error while trying to log through external program: " << external_prog << endl;
1554 log_notice(msg.str());
1560 * Error while parsing config file.
1561 * @param error Error occured.
1562 * @param config_file Config file.
1564 void Logger::print_error_parsing_config_file(const string& filename, const string& error) const
1567 if ( level <= Loglevel )
1570 msg << "Error while parsing config file: " << filename << " Error: " << error << endl;
1571 log_notice(msg.str());
1577 * Error while parsing cmd option
1578 * @param error Error
1580 void Logger::print_error_parsing_cmd(const string& error) const
1583 if ( level <= Loglevel )
1586 msg << "Error while parsing cmd options: " << error << endl;
1587 log_error(msg.str());
1593 * The webcheck interval was exceeded, so webcheck not allowed.
1594 * @param last_webcheck Time of last webcheck.
1595 * @param webcheck_interval Webcheck interval time.
1596 * @param current_time Current system time.
1598 void Logger::print_webcheck_exceed_interval( const time_t last_webcheck, const int webcheck_interval, const time_t current_time ) const
1601 if ( level <= Loglevel )
1604 msg << "Exceeding webcheck interval: LastWebcheck " << last_webcheck << " + WebcheckInterval(sec) " << webcheck_interval << " >= CurrentTime " << current_time << endl;
1605 log_notice(msg.str());
1611 * Checking if hosts needs update.
1612 * @param hostname Hostname
1613 * @param current_time Current time
1614 * @param lastupdated Last updated
1616 void Logger::print_check_service_update(const string& hostname, const time_t current_time, const time_t lastupdated) const
1619 if ( level <= Loglevel )
1622 msg << "Checking if host: " << hostname << " needs update. Current time: " << current_time << " Last updated: " << lastupdated << endl;
1623 log_notice(msg.str());
1630 * @param hostname Hostname
1631 * @param ip_dns_recheck DNS recheck IP
1632 * @param ip_last_update IP set in last update
1633 * @param ip_host Hosts' IP
1635 void Logger::print_cached_dns_entry(const string& hostname, const string& ip_dns_recheck, const string& ip_last_update, const string& ip_host) const
1638 if ( level <= Loglevel )
1641 msg << "Cached DNS record for host <" << hostname << "> : " << ip_dns_recheck << " Last updated IP: " << ip_last_update << " Hosts IP: " << ip_host << endl;
1642 log_notice(msg.str());
1648 * Updating service for the first time.
1649 * @param hostname Hostname
1650 * @param ip_dns_recheck Cached DNS entry
1651 * @param ip_host Hosts IP
1653 void Logger::print_update_service_firttime(const string& hostname, const string& ip_dns_recheck, const string& ip_host) const
1656 if ( level <= Loglevel )
1659 msg << "Updating service for the first time. Hostname: " << hostname << " DNS-Record: " << ip_dns_recheck << " Hosts IP: " << ip_host << endl;
1660 log_notice(msg.str());
1667 * @param hostname Hostname
1668 * @param ip_dns_recheck Cached DNS entry
1669 * @param ip_last_update IP set in last update
1670 * @param ip_host Hosts IP
1671 * @param lastupdated Lastupdated
1673 void Logger::print_update_service(const string& hostname, const string& ip_dns_recheck, const string& ip_last_update, const string& ip_host, const time_t lastupdated) const{
1675 if ( level <= Loglevel )
1678 msg << "Updating service. Hostname: " << hostname << " DNS-Record: " << ip_dns_recheck << " IP set in last update: " << ip_last_update << " Lastupdated: " << lastupdated << " Hosts IP: " << ip_host << endl;
1679 log_notice(msg.str());
1686 * @param hostname Hostname
1687 * @param ip_dns_recheck Cached DNS entry
1688 * @param ip_last_update IP set in last update
1689 * @param ip_host Hosts IP
1690 * @param lastupdated Last updated
1691 * @param dns_cache_ttl DNS cache ttl
1692 * @param current_time Current time
1694 void Logger::print_update_service_ttl_expired(const string& hostname, const string& ip_dns_recheck, const string& ip_last_update, const string& ip_host, const time_t lastupdated, const int dns_cache_ttl, const time_t current_time) const
1697 if ( level <= Loglevel )
1700 msg << "TTL for service expired and still pointing to old IP. Hostname: " << hostname << " DNS-Record: " << ip_dns_recheck << " IP set in last update: " << ip_last_update << " Lastupdated: " << lastupdated << "DNS Cache TTL: " << dns_cache_ttl << " Current Time: " << current_time << " Hosts IP: " << ip_host << endl;
1701 log_notice(msg.str());
1708 * @param hostname Hostname
1709 * @param ip_dns_recheck Cached DNS entry
1710 * @param ip_last_update IP set in last update
1711 * @param ip_host Hosts IP
1712 * @param lastupdated Last updated
1713 * @param dns_cache_ttl DNS cache ttl
1714 * @param current_time Current time
1716 void Logger::print_update_service_ttl_not_expired(const string& hostname, const string& ip_dns_recheck, const string& ip_last_update, const string& ip_host, const time_t lastupdated, const int dns_cache_ttl, const time_t current_time) const
1719 if ( level <= Loglevel )
1722 msg << "Waiting for DNS cache TTL to expire. Hostname: " << hostname << " DNS-Record: " << ip_dns_recheck << " IP set in last update: " << ip_last_update << " Lastupdated: " << lastupdated << "DNS Cache TTL: " << dns_cache_ttl << " Current Time: " << current_time << " Hosts IP: " << ip_host << endl;
1723 log_notice(msg.str());
1730 * @param hostname Hostname
1731 * @param ip_dns_recheck Cached DNS entry
1732 * @param ip_last_update IP set in last update
1733 * @param ip_host Hosts IP
1734 * @param lastupdated Last updated
1736 void Logger::print_no_update_needed(const string& hostname, const string& ip_dns_recheck, const string& ip_last_update, const string& ip_host, const time_t lastupdated) const
1739 if ( level <= Loglevel )
1742 msg << "No update needed for host: " << hostname << " Cached DNS record: " << ip_dns_recheck << " IP set in last update: " << ip_last_update << " Hosts IP: " << ip_host << " Last updated: " << lastupdated << endl;
1743 log_notice(msg.str());
1749 * Error while trying to get local wan interface IP address through getifaddrs.
1750 * @param error The system call which raised the error.
1751 * @param error The error set by getifaddrs.
1753 void Logger::print_error_getting_local_wan_ip(const std::string& system_call, const std::string& error) const
1756 if ( level <= Loglevel )
1759 msg << "Error while trying to get local wan interface IP address through '" << system_call << "': " << error << endl;
1760 log_error(msg.str());
1766 * Could not get IP address of local wan interface.
1768 void Logger::print_no_wan_ip() const
1771 if ( level <= Loglevel )
1774 msg << "Could not get IP address of local wan interface." << endl;
1775 log_error(msg.str());
1781 * Invalid service config was detected.
1783 void Logger::print_invalid_service_config() const
1786 if ( level <= Loglevel )
1788 log_error("Ignoring invalid service. Please check.\n");
1794 * Print simple message.
1796 void Logger::print_msg( const string& msg ) const
1799 if ( level <= Loglevel )