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)
37 set_log_facility(Loglevel,Syslog,ExternalWarningLog,ExternalWarningLevel);
50 * Decides if Logging through syslog if enabled or through std.
51 * @param msg The message to log.
53 void Logger::log_notice(const string& msg) const
56 syslog(LOG_NOTICE,msg.c_str());
63 * Decides if Logging through syslog if enabled or through std.
64 * @param msg The message to log.
66 void Logger::log_warning(const string& msg, int level) const
69 syslog(LOG_WARNING,msg.c_str());
73 if ( (level <= ExternalWarningLevel) && (!ExternalWarningLog.empty()) )
75 string external = ExternalWarningLog;
77 external.append("\"");
79 external.append("\"");
80 if ( system(external.c_str()) != 0 )
81 print_error_external_logging(external);
87 * Decides if Logging through syslog if enabled or through std.
88 * @param msg The message to log.
90 void Logger::log_error(const string& msg) const
93 syslog(LOG_ERR,msg.c_str());
100 * Setter for member Loglevel.
101 * @param _loglevel Value to set Loglevel to.
103 void Logger::set_loglevel(const int _loglevel)
105 Loglevel = _loglevel;
106 cout << "Loglevel set" << endl;
111 * Getter for member Loglevel.
114 int Logger::get_loglevel() const
121 * Setter for member Syslog.
122 * @param _syslog Wether to log through syslog or not.
124 void Logger::set_syslog(const bool _syslog)
131 * Getter for member Syslog.
132 * @return True if logging through syslog is enabled, false otherwise.
134 bool Logger::get_syslog() const
141 * Initialize the logging facility.
143 void Logger::set_log_facility(const int _loglevel, const bool _syslog, const string& _external_error_log, const int _external_error_level)
145 Loglevel = _loglevel;
147 ExternalWarningLog = _external_error_log;
148 ExternalWarningLevel = _external_error_level;
152 openlog("bpdyndnsd",LOG_PID,LOG_DAEMON);
157 * Prints out the usage to the command line.
159 void Logger::print_usage(const Options_descriptionPtr opt_desc) const
162 if ( level <= Loglevel )
165 msg << "Usage: bpdyndnsd [Command line options]" << "\n" << endl;
166 msg << *opt_desc << endl;
167 log_notice(msg.str());
173 * Prints out the programm name and the given version string on stdout.
174 * @param version Version string.
176 void Logger::print_version() const
179 if ( level <= Loglevel )
182 msg << "Bullet proof dynamic dns daemon.\nbpdyndnsd " << VERSION << "." << REVISION << "." << RELEASE << endl;
183 log_notice(msg.str());
189 * Prints out the successful parsing of the command line options.
191 void Logger::print_cmd_parsed() const
194 if ( level <= Loglevel )
196 log_notice("Command line options successfully parsed.");
201 void Logger::print_conf_files_parsed() const
204 if ( level <= Loglevel )
206 log_notice("Config files successfully parsed.");
212 * Prints out the successful parsing of the config files.
213 * @param config_path The specified config path.
215 void Logger::print_conf_loaded(const string& config_path) const
218 if ( level <= Loglevel )
221 msg << "Config files successfully loaded in: " << config_path << endl;
222 log_notice(msg.str());
228 * Prints out the unsuccessful parsing of the config files.
229 * @param config_path The specified config path.
231 void Logger::print_conf_not_loaded(const string& config_path) const
234 if ( level <= Loglevel )
237 msg << "Config files couldn't be loaded in: " << config_path << endl;
238 log_error(msg.str());
244 * A file could not be opened for reading.
245 * @param filename The filename.
247 void Logger::print_error_opening_r(const string& filename) const
250 if ( level <= Loglevel )
253 msg << "Error opening file for reading: " << filename << endl;
254 log_error(msg.str());
260 * A file could not be opened for writing.
261 * @param filename The filename.
263 void Logger::print_error_opening_rw(const string& filename) const
266 if ( level <= Loglevel )
269 msg << "Error opening file for writing: " << filename << endl;
270 log_error(msg.str());
276 * Desctructor of specified class was called.
277 * @param _class Name of the class.
279 void Logger::print_destructor_call(const string& _class) const
282 if ( level <= Loglevel )
285 msg << "Destructor call: " << _class << endl;
286 log_notice(msg.str());
292 * Constructor of specified class was called.
293 * @param _class Name of the class.
295 void Logger::print_constructor_call(const string& _class) const
298 if ( level <= Loglevel )
301 msg << "Constructor call: " << _class << endl;
302 log_notice(msg.str());
308 * Update method for specified service was called.
309 * @param service The service for which is the update running.
311 void Logger::print_update_service(const string& service) const
314 if ( level <= Loglevel )
317 msg << "Running update for service: " << service << endl;
318 log_notice(msg.str());
324 * An unknown option on the command line was detected.
325 * @param unknown_option The unknown option.
327 void Logger::print_unknown_cmd_option(const string& unknown_option) const
330 if ( level <= Loglevel )
333 msg << "Unknown option on command line detected: " << unknown_option << endl;
334 log_error(msg.str());
340 * An unknown protocol was specified.
341 * @param protocol The unknown protocol.
343 void Logger::print_unknown_protocol(const string& protocol) const
346 if ( level <= Loglevel )
349 msg << "Unknown protocol defined: " << protocol << endl;
350 log_error(msg.str());
356 * Loading a service config file.
357 * @param filename The service config file.
359 void Logger::print_load_service_conf(const string& filename) const
362 if ( level <= Loglevel )
365 msg << "Loading service config file: " << filename << endl;
366 log_notice(msg.str());
372 * Loading the main config file.
373 * @param filename The main config file.
375 void Logger::print_load_main_conf(const string& filename) const
378 if ( level <= Loglevel )
381 msg << "Loading main config file: " << filename << endl;
382 log_notice(msg.str());
388 * There is an unknown option in a service config file.
389 * @param unknown_option The unknown option.
391 void Logger::print_unknown_service_conf_option(const string& service_conf_file, const string& unknown_option) const
394 if ( level <= Loglevel )
397 msg << "Unknown option in service config file detected: " << service_conf_file << " Unknown option: " << unknown_option << endl;
398 log_error(msg.str());
404 * There is an unknown option in the main config file.
405 * @param unknown_option The unknown option.
407 void Logger::print_unknown_main_conf_option(const string& unknown_option) const
410 if ( level <= Loglevel )
413 msg << "Unknown option in main config file detected: " << unknown_option << endl;
414 log_error(msg.str());
420 * The defined config path doesn't exist or is not a directory.
421 * @param config_path The defined config path.
423 void Logger::print_error_config_path(const string& config_path) const
426 if ( level <= Loglevel )
429 msg << "Config path doesn't exists or is not a diretory: " << config_path << endl;
430 log_error(msg.str());
436 * There is a missing command line option to initialize a service object.
438 void Logger::print_missing_cmd_service_option() const
441 if ( level <= Loglevel )
443 log_error("Missing option to initialize service. Protocol, host, login and password must be specified.");
449 * Missing option in service config file.
450 * @param service_conf_file Service config file
452 void Logger::print_missing_service_conf_option(const string& service_conf_file) const
455 if ( level <= Loglevel )
458 msg << "Missing option in service config file " << service_conf_file << " to initialize service. Protocol, host, login and password must be specified." << endl;
459 log_error(msg.str());
465 * Process running as daemon.
466 * @param pid The pid of the daemon.
468 void Logger::print_runnig_as_daemon(const int pid) const
471 if ( level <= Loglevel )
474 msg << "Runnig as daemon: " << pid << endl;
475 log_notice(msg.str());
481 * Prints out the daemon mode.
482 * @param daemon_mode The daemon mode.
484 void Logger::print_daemon_mode(const bool daemon_mode) const
487 if ( level <= Loglevel )
489 string mode = "disabled";
490 if (daemon_mode == true)
493 msg << "Daemon mode is " << mode << "." << endl;
494 log_notice(msg.str());
500 * There was an error while trying to fork.
502 void Logger::print_error_fork() const
505 if ( level <= Loglevel )
507 log_error("Error while trying to fork.");
513 * A pid in the pidfile was found.
514 * @param pid The pid found in the pidfile.
516 void Logger::print_pid_found(const int pid) const
519 if ( level <= Loglevel )
522 msg << "Pidfile found: " << pid << ". Checking if process is still runnig..." << endl;
523 log_notice(msg.str());
529 * Another process is already running.
530 * @param pid The pid of the other process.
532 void Logger::print_process_already_running(const int pid) const
535 if ( level <= Loglevel )
538 msg << "Another bpdyndnsd process with PID " << pid << " is already running!" << endl;
539 log_error(msg.str());
547 void Logger::print_caught_sigterm() const
550 if ( level <= Loglevel )
552 log_notice("Caught SIGTERM. Exiting...");
560 void Logger::print_caught_siguser1() const
563 if ( level <= Loglevel )
565 log_notice("Caught SIGUSR1. Switching to offline mode...");
573 void Logger::print_caught_sighup() const
576 if ( level <= Loglevel )
578 log_notice("Caught SIGHUP. Reloading config and switching to online mode...");
584 * Error while setting signal handler.
586 void Logger::print_error_setting_signal(const string& signal) const
589 if ( level <= Loglevel )
592 msg << "Error while setting signal handler for: " << signal << endl;
593 log_error(msg.str());
599 * Error while setting signal handler.
601 void Logger::print_init_log_facility() const
604 if ( level <= Loglevel )
607 msg << "Initialized logging facility." << " Loglevel: " << Loglevel << " Syslog: " << Syslog << endl;
608 log_notice(msg.str());
614 * Be verbose. Currently we are in offline mode.
616 void Logger::print_offline_mode() const
619 if ( level <= Loglevel )
621 log_notice("Offline mode...");
627 * Objects successfully serialized.
629 void Logger::print_serialized_objects_success() const
632 if ( level <= Loglevel )
634 log_notice("Serialized objects successfully.");
640 * Objects successfully de-serialized.
642 void Logger::print_deserialized_objects_success() const
645 if ( level <= Loglevel )
647 log_notice("De-serialized objects successfully.");
653 * Prints out the content of a service object.
654 * @param message Message to be added on output first.
655 * @param protocol Service's protocol.
656 * @param hostname Service's hostname.
657 * @param login Service's login.
658 * @param password Service's password.
659 * @param actual_ip Service's actual_ip.
660 * @param lastupdated Service's lastupdated.
662 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
665 if ( level <= Loglevel )
668 msg << message << endl;
669 msg << "\t" << "Protocol: " << protocol << endl;
670 msg << "\t" << "Hostname: " << hostname << endl;
671 msg << "\t" << "Login: " << login << endl;
672 msg << "\t" << "Password: " << password << endl;
673 msg << "\t" << "Update Interval: " << update_interval << endl;
674 msg << "\t" << "Max Updates: " << max_updates_within_interval << endl;
675 msg << "\t" << "DNS Cache TTL: " << dns_cache_ttl << endl;
676 msg << "\t" << "Actual_IP: " << actual_ip << endl;
677 BOOST_FOREACH( time_t update_time, lastupdated)
679 msg << "\t" << "Lastupdated: " << update_time << endl;
681 log_notice(msg.str());
687 * Caught exception while serialize.
688 * @param exception Exception message.
690 void Logger::print_exception_serialize(const string& errMsg) const
693 if ( level <= Loglevel )
696 msg << "Error while trying to serialize Serviceholder object: " << errMsg << endl;
697 log_error(msg.str());
703 * Caught exception while de-serialize.
704 * @param exception Exception message.
706 void Logger::print_exception_deserialize(const string& errMsg) const
709 if ( level <= Loglevel )
712 msg << "Error while trying to de-serialize Serviceholder object: " << errMsg << endl;
713 log_error(msg.str());
719 * Child couldn't be killed by parent.
720 * @param pid Pid of the child.
722 void Logger::print_error_kill_child(const int pid) const
725 if ( level <= Loglevel )
728 msg << "Could not kill child process with PID: " << pid << endl;
729 log_error(msg.str());
735 * Child was killed by parent because of error.
736 * @param pid The pid (child) killed.
738 void Logger::print_child_killed(const int pid) const
741 if ( level <= Loglevel )
744 msg << "Killed child process with PID: " << pid << endl;
745 log_notice(msg.str());
751 * There is no object file.
752 * @param object_file The object file.
754 void Logger::print_no_object_file(const string& object_file) const
757 if ( (level <= Loglevel) || ((level <= ExternalWarningLevel) && (!ExternalWarningLog.empty())) )
760 msg << "There is no object file: " << object_file << ". Continue without recovering state from old services!" << endl;
761 log_warning(msg.str(),level);
767 * Prints out the given hostname
768 * @param hostname Hostname as string.
770 void Logger::print_hostname(const string& hostname) const
773 if ( level <= Loglevel )
776 msg << "Detected following hostname of localhost: " << hostname << endl;
777 log_notice(msg.str());
783 * Prints out the detected own ipv4 address
784 * @param ip_addr String representation of the detected ip.
786 void Logger::print_own_ipv4(const string& ip_addr_v4, const string& hostname) const
789 if ( level <= Loglevel )
792 msg << "Detected following IPv4-Address of host: " << hostname << " : " << ip_addr_v4 << endl;
793 log_notice(msg.str());
799 * Prints out the detected own ipv5 address
800 * @param ip_addr String representation of the detected ip.
802 void Logger::print_own_ipv6(const string& ip_addr_v6, const string& hostname) const
805 if ( level <= Loglevel )
808 msg << "Detected following IPv6-Address of host: " << hostname << " : " << ip_addr_v6 << endl;
809 log_notice(msg.str());
815 * Exception while trying to resolve hostname to ip.
816 * @param exception The exception caught.
817 * @param hostname The hostname.
819 void Logger::print_error_hostname_to_ip(const string& errMsg, const string& hostname) const
822 if ( level <= Loglevel )
825 msg << "Could not resolve the hostname: " << hostname << " to an IP-Address: " << errMsg << endl;
826 log_warning(msg.str(),level);
832 * The update of the given service was successful.
833 * @param service The service.
835 void Logger::print_update_service_successful(const string& service) const
838 if ( level <= Loglevel )
841 msg << "Updated service successful: " << service << endl;
842 log_notice(msg.str());
848 * No ip could be determined through webcheck
850 void Logger::print_webcheck_no_ip() const
853 if ( (level <= Loglevel) || ((level <= ExternalWarningLevel) && (!ExternalWarningLog.empty())) )
855 log_warning("IP-Address of this host could not be determined through any configured webcheck url.",level);
861 * Connection problem while trying to get ip through webcheck url
862 * @param curl_err_buff Curl error message
865 void Logger::print_webcheck_url_connection_problem(const char * curl_err_buff, const string& url) const
868 if ( (level <= Loglevel) || ((level <= ExternalWarningLevel) && (!ExternalWarningLog.empty())) )
871 msg << "There was a problem while trying to connect to following URL: " << url << " CURL error: " << curl_err_buff << endl;
872 log_warning(msg.str(),level);
878 * Prints out curl error.
879 * @param curl_err_buff Curl error message.
882 void Logger::print_webcheck_error(const char * curl_err_buff, const string& url) const
885 if ( level <= Loglevel )
888 msg << "There was an error while trying to connect to following URL: " << url << " CURL error: " << curl_err_buff << endl;
889 log_error(msg.str());
895 * Prints out the received data through curl.
896 * @param curl_data Data string
898 void Logger::print_received_curl_data(const string& curl_data) const
901 if ( level <= Loglevel )
904 msg << "Received CURL data: " << curl_data << endl;
905 log_notice(msg.str());
911 * IP was foudn through regex
912 * @param ip The IP found.
914 void Logger::print_regex_found_ip(const string& ip) const
917 if ( level <= Loglevel )
920 msg << "Found IP-Address via regex: " << ip << endl;
921 log_notice(msg.str());
927 * No IP was found through regex.
928 * @param data The data string which should contain a valid IP.s
930 void Logger::print_regex_ip_not_found(const string& data) const
933 if ( (level <= Loglevel) || ((level <= ExternalWarningLevel) && (!ExternalWarningLog.empty())) )
936 msg << "Could not extract an IP-Address via regex from following data:\n" << data << endl;
937 log_warning(msg.str(),level);
943 * Detected multiple occurrences of the same option.
944 * @param message Error message.
946 void Logger::print_multiple_cmd_option(const string& message) const
949 if ( level <= Loglevel )
952 msg << "The same option is only allowed once: " << message << endl;
953 log_error(msg.str());
959 * An update would exceed the update interval. Prints out a warning message.
960 * @param current_time Current time.
961 * @param old_time Time of update #MaxUpdatesWithinInterval ago.
962 * @param MaxUpdatesWithinInterval Number of allowed updates in one update interval.
963 * @param service The service which exceeds update interval.
965 void Logger::print_update_not_allowed(const int current_time, const int old_time, const int MaxUpdatesWithinInterval, const string& service) const
968 if ( (level <= Loglevel) || ((level <= ExternalWarningLevel) && (!ExternalWarningLog.empty())) )
971 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;
972 log_warning(msg.str(),level);
978 * Failure while running update for service.
979 * @param service Services' name.
981 void Logger::print_update_service_failure(const string& service) const
984 if ( (level <= Loglevel) || ((level <= ExternalWarningLevel) && (!ExternalWarningLog.empty())) )
987 msg << "Could not update service: " << service << endl;
988 log_warning(msg.str(),level);
996 void Logger::print_starting_shutdown() const
999 if ( level <= Loglevel )
1001 log_notice("Shutting down ...");
1009 void Logger::print_shutdown_succeeded() const
1012 if ( level <= Loglevel )
1014 log_notice("Shutting down complete ...");
1020 * Shutdown parent succeeded
1022 void Logger::print_shutdown_parent_succeeded() const
1025 if ( level <= Loglevel )
1027 log_notice("Shutting down parent process completed ...");
1033 * Starting shutdown parent
1035 void Logger::print_starting_shutdown_parent() const
1038 if ( level <= Loglevel )
1040 log_notice("Shutting down parent process ...");
1046 * DNS cache record timeout
1047 * @param hostname Hostname
1048 * @param lastupdated Lastupdated
1049 * @param dns_cache_ttl DNS cache TTL
1050 * @param current_time Current time
1052 void Logger::print_recheck_dns_entry(const string& hostname, const int lastupdated, const int dns_cache_ttl, const int current_time) const
1055 if ( level <= Loglevel )
1058 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;
1059 log_notice(msg.str());
1065 * Missing proxy option on command line.
1067 void Logger::print_missing_cmd_proxy_option() const
1070 if ( level <= Loglevel )
1072 log_error("Missing option to initialize proxy. http_proxy and http_proxy_port must be specified.");
1078 * Multiple option in service config file.
1079 * @param service_conf_file Service config file
1080 * @param message Multiple option text
1082 void Logger::print_multiple_service_conf_option(const string& service_conf_file, const string& message) const
1085 if ( level <= Loglevel )
1088 msg << "Multiple occurrences of the same option in service config file detected: " << service_conf_file << " " << message << endl;
1089 log_error(msg.str());
1095 * Multiple option in main config file.
1096 * @param service_conf_file Service config file
1097 * @param message Multiple option text
1099 void Logger::print_multiple_main_conf_option(const string& main_conf_file, const string& message) const
1102 if ( level <= Loglevel )
1105 msg << "Multiple occurrences of the same option in main config file detected: " << main_conf_file << " " << message << endl;
1106 log_error(msg.str());
1112 * Missing proxy option in main config file.
1113 * @param main_conf_filename The concerning config file.
1115 void Logger::print_missing_conf_proxy_option(const string& main_conf_filename) const
1118 if ( level <= Loglevel )
1121 msg << "Missing option to initialize proxy in main config file: " << main_conf_filename << " http_proxy and http_proxy_port must be specified." << endl;
1122 log_error(msg.str());
1128 * There is no domain part in the given hostname
1129 * @param hostname The hostname with no domain part in it.
1131 void Logger::print_no_domain_part(const string& hostname) const
1134 if ( level <= Loglevel )
1137 msg << "There is no domain part in the given hostname: " << hostname << endl;
1138 log_notice(msg.str());
1144 * Service is not initialized properly.
1145 * @param service The service.
1147 void Logger::print_service_not_initialized(const std::string& service) const
1150 if ( level <= Loglevel )
1153 msg << "Service: " << service << " is not initialized properly." << endl;
1154 log_warning(msg.str(),level);
1160 * An curl error occured.
1161 * @param msg The error message
1162 * @param curl_err_code The resulting curl error code
1164 void Logger::print_curl_error_init(const std::string& err_msg, const CURLcode curl_err_code) const
1166 string curl_err = "";
1168 if ( curl_err_code == CURLE_FAILED_INIT )
1169 curl_err = "CURLE_FAILED_INIT";
1171 curl_err = "UNKNOWN";
1174 if ( (level <= Loglevel) || ((level <= ExternalWarningLevel) && (!ExternalWarningLog.empty())) )
1177 msg << "Curl error: " << err_msg << " Curl error code: " << curl_err_code << " " << curl_err << endl; /*lint !e641 */
1178 log_error(msg.str());
1184 * An curl error occured.
1185 * @param url The url requested by the curl operation
1186 * @param curl_err_code The resulting curl error code
1188 void Logger::print_curl_error(const string& url, const CURLcode curl_err_code) const
1190 string curl_err = "";
1192 if ( curl_err_code == CURLE_URL_MALFORMAT )
1193 curl_err = "CURLE_URL_MALFORMAT";
1194 else if ( curl_err_code == CURLE_COULDNT_RESOLVE_HOST )
1195 curl_err = "CURLE_COULDNT_RESOLVE_HOST";
1196 else if ( curl_err_code == CURLE_COULDNT_CONNECT )
1197 curl_err = "CURLE_COULDNT_CONNECT";
1199 curl_err = "UNKNOWN";
1202 if ( (level <= Loglevel) || ((level <= ExternalWarningLevel) && (!ExternalWarningLog.empty())) )
1205 msg << "Curl error while requesting following url: " << url << " Curl error code: " << curl_err_code << " " << curl_err << endl; /*lint !e641 */
1206 log_warning(msg.str(),level);
1212 * An curl error occured.
1213 * @param url The url requested by the curl operation
1214 * @param curl_err_code The resulting curl error code
1215 * @param curl_err_buff The curl error buffer
1217 void Logger::print_curl_error(const string& url, const CURLcode curl_err_code, const char * curl_err_buff) const
1219 string curl_err = "";
1221 if ( curl_err_code == CURLE_URL_MALFORMAT )
1222 curl_err = "CURLE_URL_MALFORMAT";
1223 else if ( curl_err_code == CURLE_COULDNT_RESOLVE_HOST )
1224 curl_err = "CURLE_COULDNT_RESOLVE_HOST";
1225 else if ( curl_err_code == CURLE_COULDNT_CONNECT )
1226 curl_err = "CURLE_COULDNT_CONNECT";
1228 curl_err = "UNKNOWN";
1231 if ( (level <= Loglevel) || ((level <= ExternalWarningLevel) && (!ExternalWarningLog.empty())) )
1234 msg << "Curl error while requesting following url: " << url << " Curl error code: " << curl_err_code << " " << curl_err << " " << curl_err_buff << endl; /*lint !e641 */
1235 log_warning(msg.str(),level);
1241 * Prints out the data received by curl operation
1242 * @param CurlWritedataBuff
1244 void Logger::print_curl_data(const string& curl_writedata_buff) const
1247 if ( level <= Loglevel )
1250 msg << "Data received by curl: " << curl_writedata_buff << endl;
1251 log_notice(msg.str());
1257 * Not authorized to perform requested update operation
1258 * @param service The requested service.
1259 * @param username Username
1260 * @param password Password
1262 void Logger::print_service_not_authorized(const string& service, const string& username, const string& password) const
1265 if ( (level <= Loglevel) || ((level <= ExternalWarningLevel) && (!ExternalWarningLog.empty())) )
1268 msg << "Not authorized to perform update operation on service: " << service << " Please check username and password: " << username << ":" << password << endl;
1269 log_warning(msg.str(),level);
1275 * Prints out the http status code
1277 * @param output HTTP status code
1279 void Logger::print_http_status_code(const string& url, const long http_code) const
1282 if ( level <= Loglevel )
1285 msg << "Requested URL: " << url << " Received HTTP status code: " << http_code << endl;
1286 log_notice(msg.str());
1292 * Generic failure while trying to update service
1293 * @param url The requested URL
1294 * @param curl_data The received curl_data from the server
1296 void Logger::print_update_failure(const string& url, const string& curl_data) const
1299 if ( (level <= Loglevel) || ((level <= ExternalWarningLevel) && (!ExternalWarningLog.empty())) )
1302 msg << "Problem while trying to updating service. Requested URL: " << url << " Error Code from Server: " << curl_data << endl;
1303 log_warning(msg.str(),level);
1309 * Generic failure while trying to update service
1310 * @param url The requested URL
1311 * @param http_status_code The received http status code
1313 void Logger::print_update_failure(const string& url, const long http_status_code) const
1316 if ( (level <= Loglevel) || ((level <= ExternalWarningLevel) && (!ExternalWarningLog.empty())) )
1319 msg << "Problem while trying to updating service. Requested URL: " << url << " Error Code from Server: " << http_status_code << endl;
1320 log_warning(msg.str(),level);
1325 * Hostname is invalid, contains no or only one domain part.
1326 * @param hostname The full qualified host name.
1328 void Logger::print_invalid_hostname(const string& hostname) const
1331 if ( (level <= Loglevel) || ((level <= ExternalWarningLevel) && (!ExternalWarningLog.empty())) )
1334 msg << "The configured hostname: " << hostname << " is invalid. Please add the corresponding domain part." << endl;
1335 log_warning(msg.str(),level);
1341 * An IP in a private range was detected
1342 * @param ip The private IP
1344 void Logger::print_ip_is_local(const string& ip) const
1347 if ( (level <= Loglevel) || ((level <= ExternalWarningLevel) && (!ExternalWarningLog.empty())) )
1350 msg << "The detected IP is within a private IP range: " << ip << endl;
1351 log_warning(msg.str(),level);
1357 * Regex is matching in string
1358 * @param regex The regex pattern
1359 * @param matching_string The string
1361 void Logger::print_regex_match(const string& regex, const string& matching_string) const
1364 if ( level <= Loglevel )
1367 msg << "Regex: " << regex << " is matching in: " << matching_string << endl;
1368 log_notice(msg.str());
1374 * Regex is not matching
1375 * @param regex Regex
1376 * @param not_matching_string String
1378 void Logger::print_no_regex_match(const string& regex, const string& not_matching_string) const
1381 if ( (level <= Loglevel) || ((level <= ExternalWarningLevel) && (!ExternalWarningLog.empty())) )
1384 msg << "Regex: " << regex << " is not matching in: " << not_matching_string << endl;
1385 log_warning(msg.str(),level);
1391 * Could not parse gnudip initial reply.
1392 * @param curl_data The data received from gnudip server which should contain salt, time and sign.
1394 void Logger::print_could_not_parse_received_data(const string& curl_data) const
1397 if ( (level <= Loglevel) || ((level <= ExternalWarningLevel) && (!ExternalWarningLog.empty())) )
1400 msg << "Could not parse salt, time and sign from initial gnudip server reply: " << curl_data << endl;
1401 log_warning(msg.str(),level);
1407 * Gnudip salt, time and sign could not be got from map
1409 void Logger::print_could_not_get_initial_gnudip_data() const
1412 if ( (level <= Loglevel) || ((level <= ExternalWarningLevel) && (!ExternalWarningLog.empty())) )
1414 log_warning("Could not get salt, time and sign from map.",level);
1421 * Gnudip protocol requires explicit declaration of a servername.
1423 void Logger::print_gnudip_requires_servername() const
1426 if ( (level <= Loglevel) || ((level <= ExternalWarningLevel) && (!ExternalWarningLog.empty())) )
1428 log_warning("Gnudip requires explicit definition of servername via config!",level);
1434 * An exception occured while computing the md5 sum.
1435 * @param what The exception occured.
1437 void Logger::print_exception_md5_sum(const string& what) const
1440 if ( level <= Loglevel )
1443 msg << "An exception occured while computing a md5 sum: " << what << endl;
1444 log_error(msg.str());
1450 * An network exception occured.
1451 * @param what The exception occured.
1453 void Logger::print_network_error(const string& what) const
1456 if ( level <= Loglevel )
1459 msg << "An netowrk exception occured: " << what << endl;
1460 log_error(msg.str());
1466 * An undefined protocol error occured.
1467 * @param protocol The protocol
1468 * @param error The error
1470 void Logger::print_undefined_protocol_error(const string& protocol, const string& error) const
1473 if ( level <= Loglevel )
1476 msg << "An undefined protocol error occured. Protocol: " << protocol << " Error: " << error << endl;
1477 log_error(msg.str());
1482 * Error while trying to log through external program.
1483 * @param external_prog The external program called.
1485 void Logger::print_error_external_logging(const string& external_prog) const
1488 if ( level <= Loglevel )
1491 msg << "Error while trying to log through external program: " << external_prog << endl;
1492 log_notice(msg.str());
1498 * Error while parsing config file.
1499 * @param error Error occured.
1500 * @param config_file Config file.
1502 void Logger::print_error_parsing_config_file(const string& filename, const string& error) const
1505 if ( level <= Loglevel )
1508 msg << "Error while parsing config file: " << filename << " Error: " << error << endl;
1509 log_notice(msg.str());
1515 * Error while parsing cmd option
1516 * @param error Error
1518 void Logger::print_error_parsing_cmd(const string& error) const
1521 if ( level <= Loglevel )
1524 msg << "Error while parsing cmd options: " << error << endl;
1525 log_error(msg.str());
1531 * The webcheck interval was exceeded, so webcheck not allowed.
1532 * @param last_webcheck Time of last webcheck.
1533 * @param webcheck_interval Webcheck interval time.
1534 * @param current_time Current system time.
1536 void Logger::print_webcheck_exceed_interval( const time_t last_webcheck, const int webcheck_interval, const time_t current_time ) const
1539 if ( level <= Loglevel )
1542 msg << "Exceeding webcheck interval: LastWebcheck " << last_webcheck << " + WebcheckInterval(sec) " << webcheck_interval << " >= CurrentTime " << current_time << endl;
1543 log_notice(msg.str());
1549 * Checking if hosts needs update.
1550 * @param hostname Hostname
1551 * @param current_time Current time
1552 * @param lastupdated Last updated
1554 void Logger::print_check_service_update(const string& hostname, const time_t current_time, const time_t lastupdated) const
1557 if ( level <= Loglevel )
1560 msg << "Checking if host: " << hostname << " needs update. Current time: " << current_time << " Last updated: " << lastupdated << endl;
1561 log_notice(msg.str());
1568 * @param hostname Hostname
1569 * @param ip_dns_recheck DNS recheck IP
1570 * @param ip_last_update IP set in last update
1571 * @param ip_host Hosts' IP
1573 void Logger::print_cached_dns_entry(const string& hostname, const string& ip_dns_recheck, const string& ip_last_update, const string& ip_host) const
1576 if ( level <= Loglevel )
1579 msg << "Cached DNS record for host <" << hostname << "> : " << ip_dns_recheck << " Last updated IP: " << ip_last_update << " Hosts IP: " << ip_host << endl;
1580 log_notice(msg.str());
1586 * Updating service for the first time.
1587 * @param hostname Hostname
1588 * @param ip_dns_recheck Cached DNS entry
1589 * @param ip_host Hosts IP
1591 void Logger::print_update_service_firttime(const string& hostname, const string& ip_dns_recheck, const string& ip_host) const
1594 if ( level <= Loglevel )
1597 msg << "Updating service for the first time. Hostname: " << hostname << " DNS-Record: " << ip_dns_recheck << " Hosts IP: " << ip_host << endl;
1598 log_notice(msg.str());
1605 * @param hostname Hostname
1606 * @param ip_dns_recheck Cached DNS entry
1607 * @param ip_last_update IP set in last update
1608 * @param ip_host Hosts IP
1609 * @param lastupdated Lastupdated
1611 void Logger::print_update_service(const string& hostname, const string& ip_dns_recheck, const string& ip_last_update, const string& ip_host, const int lastupdated) const{
1613 if ( level <= Loglevel )
1616 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;
1617 log_notice(msg.str());
1624 * @param hostname Hostname
1625 * @param ip_dns_recheck Cached DNS entry
1626 * @param ip_last_update IP set in last update
1627 * @param ip_host Hosts IP
1628 * @param lastupdated Last updated
1629 * @param dns_cache_ttl DNS cache ttl
1630 * @param current_time Current time
1632 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 int lastupdated, const int dns_cache_ttl, const int current_time) const
1635 if ( level <= Loglevel )
1638 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;
1639 log_notice(msg.str());
1646 * @param hostname Hostname
1647 * @param ip_dns_recheck Cached DNS entry
1648 * @param ip_last_update IP set in last update
1649 * @param ip_host Hosts IP
1650 * @param lastupdated Last updated
1651 * @param dns_cache_ttl DNS cache ttl
1652 * @param current_time Current time
1654 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 int lastupdated, const int dns_cache_ttl, const int current_time) const
1657 if ( level <= Loglevel )
1660 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;
1661 log_notice(msg.str());
1668 * @param hostname Hostname
1669 * @param ip_dns_recheck Cached DNS entry
1670 * @param ip_last_update IP set in last update
1671 * @param ip_host Hosts IP
1672 * @param lastupdated Last updated
1674 void Logger::print_no_update_needed(const string& hostname, const string& ip_dns_recheck, const string& ip_last_update, const string& ip_host, const int lastupdated) const
1677 if ( level <= Loglevel )
1680 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;
1681 log_notice(msg.str());
1687 * Error while trying to get local wan interface IP address through getifaddrs.
1688 * @param error The system call which raised the error.
1689 * @param error The error set by getifaddrs.
1691 void Logger::print_error_getting_local_wan_ip(const std::string& system_call, const std::string& error) const
1694 if ( level <= Loglevel )
1697 msg << "Error while trying to get local wan interface IP address through '" << system_call << "': " << error << endl;
1698 log_error(msg.str());
1704 * Could not get IP address of local wan interface.
1706 void Logger::print_no_wan_ip() const
1709 if ( level <= Loglevel )
1712 msg << "Could not get IP address of local wan interface." << endl;
1713 log_error(msg.str());