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 * Escape shell arguments.
86 * @param input The input to escape.
87 * @return The escaped string ready to use for the shell.
89 string Logger::escape_shellarg(const string &input)
92 string::const_iterator it, it_end = input.end();
93 for (it = input.begin(); it != it_end; it++)
107 * Decides if Logging through syslog if enabled or through std.
108 * @param msg The message to log.
110 void Logger::log_warning(const string& msg, int level)
113 syslog(LOG_WARNING,msg.c_str());
117 if ( (level <= ExternalWarningLevel) && (!ExternalWarningLog.empty()) && (is_allowed_to_send(msg)) )
119 string message = msg;
120 // Remove endline from msg.
121 if (!message.empty() && message[message.length()-1] == '\n')
122 message.erase(message.length()-1); /*lint !e534 */
124 message = escape_shellarg(message);
126 string external = ExternalWarningLog;
127 external.append(" ");
128 external.append(message);
129 if ( system(external.c_str()) != 0 )
130 print_error_external_logging(external);
132 ExternalSendMessages.insert(msg); /*lint !e534 */
138 * Decides if Logging through syslog if enabled or through std.
139 * @param msg The message to log.
141 void Logger::log_error(const string& msg) const
144 syslog(LOG_ERR,msg.c_str());
151 * Setter for member Loglevel.
152 * @param _loglevel Value to set Loglevel to.
154 void Logger::set_external_log_only_once( const bool _external_log_only_once )
156 ExternalLogOnlyOnce = _external_log_only_once;
161 * Setter for member Loglevel.
162 * @param _loglevel Value to set Loglevel to.
164 void Logger::set_loglevel(const int _loglevel)
166 Loglevel = _loglevel;
171 * Getter for member Loglevel.
174 int Logger::get_loglevel() const
181 * Setter for member Syslog.
182 * @param _syslog Wether to log through syslog or not.
184 void Logger::set_syslog(const bool _syslog)
191 * Getter for member Syslog.
192 * @return True if logging through syslog is enabled, false otherwise.
194 bool Logger::get_syslog() const
201 * Initialize the logging facility.
203 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 )
205 Loglevel = _loglevel;
207 ExternalWarningLog = _external_error_log;
208 ExternalWarningLevel = _external_error_level;
209 ExternalLogOnlyOnce = _external_log_only_once;
212 openlog("bpdyndnsd",LOG_PID,LOG_DAEMON);
217 * Prints out the usage to the command line.
219 void Logger::print_usage(const Options_descriptionPtr opt_desc) const
222 if ( level <= Loglevel )
225 msg << "Usage: bpdyndnsd [Command line options]" << "\n" << endl;
226 msg << *opt_desc << endl;
227 log_notice(msg.str());
233 * Prints out the programm name and the given version string on stdout.
234 * @param version Version string.
236 void Logger::print_version() const
239 if ( level <= Loglevel )
242 msg << "Bullet proof dynamic dns daemon.\nbpdyndnsd " << VERSION << "." << REVISION << "." << RELEASE << endl;
243 log_notice(msg.str());
249 * Prints out the successful parsing of the command line options.
251 void Logger::print_cmd_parsed() const
254 if ( level <= Loglevel )
256 log_notice("Command line options successfully parsed.");
261 void Logger::print_conf_files_parsed() const
264 if ( level <= Loglevel )
266 log_notice("Config files successfully parsed.");
272 * Prints out the successful parsing of the config files.
273 * @param config_path The specified config path.
275 void Logger::print_conf_loaded(const string& config_path) const
278 if ( level <= Loglevel )
281 msg << "Config files successfully loaded in: " << config_path << endl;
282 log_notice(msg.str());
288 * Prints out the unsuccessful parsing of the config files.
289 * @param config_path The specified config path.
291 void Logger::print_conf_not_loaded(const string& config_path) const
294 if ( level <= Loglevel )
297 msg << "Config files couldn't be loaded in: " << config_path << endl;
298 log_error(msg.str());
304 * A file could not be opened for reading.
305 * @param filename The filename.
307 void Logger::print_error_opening_r(const string& filename) const
310 if ( level <= Loglevel )
313 msg << "Error opening file for reading: " << filename << endl;
314 log_error(msg.str());
320 * A file could not be opened for writing.
321 * @param filename The filename.
323 void Logger::print_error_opening_rw(const string& filename) const
326 if ( level <= Loglevel )
329 msg << "Error opening file for writing: " << filename << endl;
330 log_error(msg.str());
336 * Desctructor of specified class was called.
337 * @param _class Name of the class.
339 void Logger::print_destructor_call(const string& _class) const
342 if ( level <= Loglevel )
345 msg << "Destructor call: " << _class << endl;
346 log_notice(msg.str());
352 * Constructor of specified class was called.
353 * @param _class Name of the class.
355 void Logger::print_constructor_call(const string& _class) const
358 if ( level <= Loglevel )
361 msg << "Constructor call: " << _class << endl;
362 log_notice(msg.str());
368 * Update method for specified service was called.
369 * @param service The service for which is the update running.
371 void Logger::print_update_service(const string& service) const
374 if ( level <= Loglevel )
377 msg << "Running update for service: " << service << endl;
378 log_notice(msg.str());
384 * An unknown option on the command line was detected.
385 * @param unknown_option The unknown option.
387 void Logger::print_unknown_cmd_option(const string& unknown_option) const
390 if ( level <= Loglevel )
393 msg << "Unknown option on command line detected: " << unknown_option << endl;
394 log_error(msg.str());
400 * An unknown protocol was specified.
401 * @param protocol The unknown protocol.
403 void Logger::print_unknown_protocol(const string& protocol) const
406 if ( level <= Loglevel )
409 msg << "Unknown protocol defined: " << protocol << endl;
410 log_error(msg.str());
416 * Loading a service config file.
417 * @param filename The service config file.
419 void Logger::print_load_service_conf(const string& filename) const
422 if ( level <= Loglevel )
425 msg << "Loading service config file: " << filename << endl;
426 log_notice(msg.str());
432 * Loading the main config file.
433 * @param filename The main config file.
435 void Logger::print_load_main_conf(const string& filename) const
438 if ( level <= Loglevel )
441 msg << "Loading main config file: " << filename << endl;
442 log_notice(msg.str());
448 * There is an unknown option in a service config file.
449 * @param unknown_option The unknown option.
451 void Logger::print_unknown_service_conf_option(const string& service_conf_file, const string& unknown_option) const
454 if ( level <= Loglevel )
457 msg << "Unknown option in service config file detected: " << service_conf_file << " Unknown option: " << unknown_option << endl;
458 log_error(msg.str());
464 * There is an unknown option in the main config file.
465 * @param unknown_option The unknown option.
467 void Logger::print_unknown_main_conf_option(const string& unknown_option) const
470 if ( level <= Loglevel )
473 msg << "Unknown option in main config file detected: " << unknown_option << endl;
474 log_error(msg.str());
480 * The defined config path doesn't exist or is not a directory.
481 * @param config_path The defined config path.
483 void Logger::print_error_config_path(const string& config_path) const
486 if ( level <= Loglevel )
489 msg << "Config path doesn't exists or is not a diretory: " << config_path << endl;
490 log_error(msg.str());
496 * There is a missing command line option to initialize a service object.
498 void Logger::print_missing_cmd_service_option() const
501 if ( level <= Loglevel )
503 log_error("Missing option to initialize service. Protocol, host, login and password must be specified.");
509 * Missing option in service config file.
510 * @param service_conf_file Service config file
512 void Logger::print_missing_service_conf_option(const string& service_conf_file) const
515 if ( level <= Loglevel )
518 msg << "Missing option in service config file " << service_conf_file << " to initialize service. Protocol, host, login and password must be specified." << endl;
519 log_error(msg.str());
525 * Process running as daemon.
526 * @param pid The pid of the daemon.
528 void Logger::print_runnig_as_daemon(const int pid) const
531 if ( level <= Loglevel )
534 msg << "Runnig as daemon: " << pid << endl;
535 log_notice(msg.str());
541 * Prints out the daemon mode.
542 * @param daemon_mode The daemon mode.
544 void Logger::print_daemon_mode(const bool daemon_mode) const
547 if ( level <= Loglevel )
549 string mode = "disabled";
550 if (daemon_mode == true)
553 msg << "Daemon mode is " << mode << "." << endl;
554 log_notice(msg.str());
560 * There was an error while trying to fork.
562 void Logger::print_error_fork() const
565 if ( level <= Loglevel )
567 log_error("Error while trying to fork.");
573 * A pid in the pidfile was found.
574 * @param pid The pid found in the pidfile.
576 void Logger::print_pid_found(const int pid) const
579 if ( level <= Loglevel )
582 msg << "Pidfile found: " << pid << ". Checking if process is still runnig..." << endl;
583 log_notice(msg.str());
589 * Another process is already running.
590 * @param pid The pid of the other process.
592 void Logger::print_process_already_running(const int pid) const
595 if ( level <= Loglevel )
598 msg << "Another bpdyndnsd process with PID " << pid << " is already running!" << endl;
599 log_error(msg.str());
607 void Logger::print_caught_sigterm() const
610 if ( level <= Loglevel )
612 log_notice("Caught SIGTERM. Exiting...");
620 void Logger::print_caught_siguser1() const
623 if ( level <= Loglevel )
625 log_notice("Caught SIGUSR1. Switching to offline mode...");
633 void Logger::print_caught_sighup() const
636 if ( level <= Loglevel )
638 log_notice("Caught SIGHUP. Reloading config...");
646 void Logger::print_caught_siguser2() const
649 if ( level <= Loglevel )
651 log_notice("Caught SIGUSR2. Switching to online mode...");
659 void Logger::print_caught_sigrtmin() const
662 if ( level <= Loglevel )
664 log_notice("Caught SIGRTMIN. Switching to online mode with webcheck enabled...");
670 * Error while setting signal handler.
672 void Logger::print_error_setting_signal(const string& signal) const
675 if ( level <= Loglevel )
678 msg << "Error while setting signal handler for: " << signal << endl;
679 log_error(msg.str());
685 * Error while setting signal handler.
687 void Logger::print_init_log_facility() const
690 if ( level <= Loglevel )
693 msg << "Initialized logging facility." << " Loglevel: " << Loglevel << " Syslog: " << Syslog << " ExternalLogOnlyOnce: " << ExternalLogOnlyOnce << endl;
694 log_notice(msg.str());
700 * Be verbose. Currently we are in offline mode.
702 void Logger::print_offline_mode() const
705 if ( level <= Loglevel )
707 log_notice("Offline mode...");
713 * Objects successfully serialized.
715 void Logger::print_serialized_objects_success() const
718 if ( level <= Loglevel )
720 log_notice("Serialized objects successfully.");
726 * Objects successfully de-serialized.
728 void Logger::print_deserialized_objects_success() const
731 if ( level <= Loglevel )
733 log_notice("De-serialized objects successfully.");
739 * Prints out the content of a service object.
740 * @param message Message to be added on output first.
741 * @param protocol Service's protocol.
742 * @param hostname Service's hostname.
743 * @param login Service's login.
744 * @param password Service's password.
745 * @param actual_ip Service's actual_ip.
746 * @param lastupdated Service's lastupdated.
748 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
751 if ( level <= Loglevel )
754 msg << message << endl;
755 msg << "\t" << "Protocol: " << protocol << endl;
756 msg << "\t" << "Hostname: " << hostname << endl;
757 msg << "\t" << "Login: " << login << endl;
758 msg << "\t" << "Password: " << password << endl;
759 msg << "\t" << "Update Interval: " << update_interval << endl;
760 msg << "\t" << "Max Updates: " << max_updates_within_interval << endl;
761 msg << "\t" << "DNS Cache TTL: " << dns_cache_ttl << endl;
762 msg << "\t" << "Actual_IP: " << actual_ip << endl;
763 BOOST_FOREACH( time_t update_time, lastupdated)
765 msg << "\t" << "Lastupdated: " << update_time << endl;
767 log_notice(msg.str());
773 * Caught exception while serialize.
774 * @param exception Exception message.
776 void Logger::print_exception_serialize(const string& errMsg) const
779 if ( level <= Loglevel )
782 msg << "Error while trying to serialize Serviceholder object: " << errMsg << endl;
783 log_error(msg.str());
789 * Caught exception while de-serialize.
790 * @param exception Exception message.
792 void Logger::print_exception_deserialize(const string& errMsg) const
795 if ( level <= Loglevel )
798 msg << "Error while trying to de-serialize Serviceholder object: " << errMsg << endl;
799 log_error(msg.str());
805 * Child couldn't be killed by parent.
806 * @param pid Pid of the child.
808 void Logger::print_error_kill_child(const int pid) const
811 if ( level <= Loglevel )
814 msg << "Could not kill child process with PID: " << pid << endl;
815 log_error(msg.str());
821 * Child was killed by parent because of error.
822 * @param pid The pid (child) killed.
824 void Logger::print_child_killed(const int pid) const
827 if ( level <= Loglevel )
830 msg << "Killed child process with PID: " << pid << endl;
831 log_notice(msg.str());
837 * There is no object file.
838 * @param object_file The object file.
840 void Logger::print_no_object_file(const string& object_file)
843 if ( (level <= Loglevel) || ((level <= ExternalWarningLevel) && (!ExternalWarningLog.empty())) )
846 msg << "There is no object file: " << object_file << ". Continue without recovering state from old services!" << endl;
847 log_warning(msg.str(),level);
853 * Prints out the given hostname
854 * @param hostname Hostname as string.
856 void Logger::print_hostname(const string& hostname) const
859 if ( level <= Loglevel )
862 msg << "Detected following hostname of localhost: " << hostname << endl;
863 log_notice(msg.str());
869 * Prints out the detected own ipv4 address
870 * @param ip_addr String representation of the detected ip.
872 void Logger::print_own_ipv4(const string& ip_addr_v4, const string& hostname) const
875 if ( level <= Loglevel )
878 msg << "Detected following IPv4-Address of host: " << hostname << " : " << ip_addr_v4 << endl;
879 log_notice(msg.str());
885 * Prints out the detected own ipv5 address
886 * @param ip_addr String representation of the detected ip.
888 void Logger::print_own_ipv6(const string& ip_addr_v6, const string& hostname) const
891 if ( level <= Loglevel )
894 msg << "Detected following IPv6-Address of host: " << hostname << " : " << ip_addr_v6 << endl;
895 log_notice(msg.str());
901 * Exception while trying to resolve hostname to ip.
902 * @param exception The exception caught.
903 * @param hostname The hostname.
905 void Logger::print_error_hostname_to_ip(const string& errMsg, const string& hostname) const
908 if ( level <= Loglevel )
911 msg << "Could not resolve the hostname: " << hostname << " to an IP-Address: " << errMsg << endl;
912 log_error(msg.str());
918 * The update of the given service was successful.
919 * @param service The service.
921 void Logger::print_update_service_successful(const string& service) const
924 if ( level <= Loglevel )
927 msg << "Updated service successful: " << service << endl;
928 log_notice(msg.str());
934 * No ip could be determined through webcheck
936 void Logger::print_webcheck_no_ip()
939 if ( (level <= Loglevel) || ((level <= ExternalWarningLevel) && (!ExternalWarningLog.empty())) )
941 log_warning("IP-Address of this host could not be determined through any configured webcheck url.",level);
947 * Connection problem while trying to get ip through webcheck url
948 * @param curl_err_buff Curl error message
951 void Logger::print_webcheck_url_connection_problem(const char * curl_err_buff, const string& url)
954 if ( (level <= Loglevel) || ((level <= ExternalWarningLevel) && (!ExternalWarningLog.empty())) )
957 msg << "There was a problem while trying to connect to following URL: " << url << " CURL error: " << curl_err_buff << endl;
958 log_warning(msg.str(),level);
964 * Prints out curl error.
965 * @param curl_err_buff Curl error message.
968 void Logger::print_webcheck_error(const char * curl_err_buff, const string& url) const
971 if ( level <= Loglevel )
974 msg << "There was an error while trying to connect to following URL: " << url << " CURL error: " << curl_err_buff << endl;
975 log_error(msg.str());
981 * Prints out the received data through curl.
982 * @param curl_data Data string
984 void Logger::print_received_curl_data(const string& curl_data) const
987 if ( level <= Loglevel )
990 msg << "Received CURL data: " << curl_data << endl;
991 log_notice(msg.str());
997 * IP was foudn through regex
998 * @param ip The IP found.
1000 void Logger::print_regex_found_ip(const string& ip) const
1003 if ( level <= Loglevel )
1006 msg << "Found IP-Address via regex: " << ip << endl;
1007 log_notice(msg.str());
1013 * No IP was found through regex.
1014 * @param data The data string which should contain a valid IP.s
1016 void Logger::print_regex_ip_not_found(const string& data)
1019 if ( (level <= Loglevel) || ((level <= ExternalWarningLevel) && (!ExternalWarningLog.empty())) )
1022 msg << "Could not extract an IP-Address via regex from following data:\n" << data << endl;
1023 log_warning(msg.str(),level);
1029 * Detected multiple occurrences of the same option.
1030 * @param message Error message.
1032 void Logger::print_multiple_cmd_option(const string& message) const
1035 if ( level <= Loglevel )
1038 msg << "The same option is only allowed once: " << message << endl;
1039 log_error(msg.str());
1045 * An update would exceed the update interval. Prints out a warning message.
1046 * @param current_time Current time.
1047 * @param old_time Time of update #MaxUpdatesWithinInterval ago.
1048 * @param MaxUpdatesWithinInterval Number of allowed updates in one update interval.
1049 * @param service The service which exceeds update interval.
1051 void Logger::print_update_not_allowed(const time_t current_time, const time_t old_time, const int MaxUpdatesWithinInterval, const string& service)
1054 if ( (level <= Loglevel) || ((level <= ExternalWarningLevel) && (!ExternalWarningLog.empty())) )
1057 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;
1058 log_warning(msg.str(),level);
1064 * Failure while running update for service.
1065 * @param service Services' name.
1067 void Logger::print_update_service_failure(const string& service)
1070 if ( (level <= Loglevel) || ((level <= ExternalWarningLevel) && (!ExternalWarningLog.empty())) )
1073 msg << "Could not update service: " << service << endl;
1074 log_warning(msg.str(),level);
1082 void Logger::print_starting_shutdown() const
1085 if ( level <= Loglevel )
1087 log_notice("Shutting down ...");
1095 void Logger::print_shutdown_succeeded() const
1098 if ( level <= Loglevel )
1100 log_notice("Shutting down complete ...");
1106 * Shutdown parent succeeded
1108 void Logger::print_shutdown_parent_succeeded() const
1111 if ( level <= Loglevel )
1113 log_notice("Shutting down parent process completed ...");
1119 * Starting shutdown parent
1121 void Logger::print_starting_shutdown_parent() const
1124 if ( level <= Loglevel )
1126 log_notice("Shutting down parent process ...");
1132 * DNS cache record timeout
1133 * @param hostname Hostname
1134 * @param lastupdated Lastupdated
1135 * @param dns_cache_ttl DNS cache TTL
1136 * @param current_time Current time
1138 void Logger::print_recheck_dns_entry(const string& hostname, const int lastupdated, const int dns_cache_ttl, const int current_time) const
1141 if ( level <= Loglevel )
1144 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;
1145 log_notice(msg.str());
1151 * Missing proxy option on command line.
1153 void Logger::print_missing_cmd_proxy_option() const
1156 if ( level <= Loglevel )
1158 log_error("Missing option to initialize proxy. http_proxy and http_proxy_port must be specified.");
1164 * Multiple option in service config file.
1165 * @param service_conf_file Service config file
1166 * @param message Multiple option text
1168 void Logger::print_multiple_service_conf_option(const string& service_conf_file, const string& message) const
1171 if ( level <= Loglevel )
1174 msg << "Multiple occurrences of the same option in service config file detected: " << service_conf_file << " " << message << endl;
1175 log_error(msg.str());
1181 * Multiple option in main config file.
1182 * @param service_conf_file Service config file
1183 * @param message Multiple option text
1185 void Logger::print_multiple_main_conf_option(const string& main_conf_file, const string& message) const
1188 if ( level <= Loglevel )
1191 msg << "Multiple occurrences of the same option in main config file detected: " << main_conf_file << " " << message << endl;
1192 log_error(msg.str());
1198 * Missing proxy option in main config file.
1199 * @param main_conf_filename The concerning config file.
1201 void Logger::print_missing_conf_proxy_option(const string& main_conf_filename) const
1204 if ( level <= Loglevel )
1207 msg << "Missing option to initialize proxy in main config file: " << main_conf_filename << " http_proxy and http_proxy_port must be specified." << endl;
1208 log_error(msg.str());
1214 * There is no domain part in the given hostname
1215 * @param hostname The hostname with no domain part in it.
1217 void Logger::print_no_domain_part(const string& hostname) const
1220 if ( level <= Loglevel )
1223 msg << "There is no domain part in the given hostname: " << hostname << endl;
1224 log_notice(msg.str());
1230 * Service is not initialized properly.
1231 * @param service The service.
1233 void Logger::print_httphelper_not_initialized() const
1236 if ( level <= Loglevel )
1238 log_error("HTTP-Helper is not initialized properly.");
1244 * An curl error occured.
1245 * @param msg The error message
1246 * @param curl_err_code The resulting curl error code
1248 void Logger::print_curl_error_init(const std::string& err_msg, const CURLcode curl_err_code) const
1250 string curl_err = "";
1252 if ( curl_err_code == CURLE_FAILED_INIT )
1253 curl_err = "CURLE_FAILED_INIT";
1255 curl_err = "UNKNOWN";
1258 if ( (level <= Loglevel) )
1261 msg << "Curl error: " << err_msg << " Curl error code: " << curl_err_code << " " << curl_err << endl; /*lint !e641 */
1262 log_error(msg.str());
1268 * An curl error occured.
1269 * @param url The url requested by the curl operation
1270 * @param curl_err_code The resulting curl error code
1272 void Logger::print_curl_error(const string& url, const CURLcode curl_err_code) const
1274 string curl_err = "";
1276 if ( curl_err_code == CURLE_URL_MALFORMAT )
1277 curl_err = "CURLE_URL_MALFORMAT";
1278 else if ( curl_err_code == CURLE_COULDNT_RESOLVE_HOST )
1279 curl_err = "CURLE_COULDNT_RESOLVE_HOST";
1280 else if ( curl_err_code == CURLE_COULDNT_CONNECT )
1281 curl_err = "CURLE_COULDNT_CONNECT";
1283 curl_err = "UNKNOWN";
1286 if ( (level <= Loglevel) )
1289 msg << "Curl error while requesting following url: " << url << " Curl error code: " << curl_err_code << " " << curl_err << endl; /*lint !e641 */
1290 log_error(msg.str());
1296 * An curl error occured.
1297 * @param url The url requested by the curl operation
1298 * @param curl_err_code The resulting curl error code
1299 * @param curl_err_buff The curl error buffer
1301 void Logger::print_curl_error(const string& url, const CURLcode curl_err_code, const char * curl_err_buff) const
1303 string curl_err = "";
1305 if ( curl_err_code == CURLE_URL_MALFORMAT )
1306 curl_err = "CURLE_URL_MALFORMAT";
1307 else if ( curl_err_code == CURLE_COULDNT_RESOLVE_HOST )
1308 curl_err = "CURLE_COULDNT_RESOLVE_HOST";
1309 else if ( curl_err_code == CURLE_COULDNT_CONNECT )
1310 curl_err = "CURLE_COULDNT_CONNECT";
1312 curl_err = "UNKNOWN";
1315 if ( (level <= Loglevel) )
1318 msg << "Curl error while requesting following url: " << url << " Curl error code: " << curl_err_code << " " << curl_err << " " << curl_err_buff << endl; /*lint !e641 */
1319 log_error(msg.str());
1325 * Prints out the data received by curl operation
1326 * @param CurlWritedataBuff
1328 void Logger::print_curl_data(const string& curl_writedata_buff) const
1331 if ( level <= Loglevel )
1334 msg << "Data received by curl: " << curl_writedata_buff << endl;
1335 log_notice(msg.str());
1341 * Not authorized to perform requested update operation
1342 * @param service The requested service.
1343 * @param username Username
1344 * @param password Password
1346 void Logger::print_service_not_authorized(const string& service, const string& username, const string& password) const
1349 if ( level <= Loglevel )
1352 msg << "Not authorized to perform update operation on service: " << service << " Please check username and password: " << username << ":" << password << endl;
1353 log_notice(msg.str());
1359 * Prints out the http status code
1361 * @param output HTTP status code
1363 void Logger::print_http_status_code(const string& url, const long http_code) const
1366 if ( level <= Loglevel )
1369 msg << "Requested URL: " << url << " Received HTTP status code: " << http_code << endl;
1370 log_notice(msg.str());
1376 * Generic failure while trying to update service
1377 * @param url The requested URL
1378 * @param curl_data The received curl_data from the server
1380 void Logger::print_update_failure(const string& url, const string& curl_data) const
1383 if ( (level <= Loglevel) )
1386 msg << "Problem while trying to updating service. Requested URL: " << url << " Error Code from Server: " << curl_data << endl;
1387 log_error(msg.str());
1393 * Generic failure while trying to update service
1394 * @param url The requested URL
1395 * @param http_status_code The received http status code
1397 void Logger::print_update_failure(const string& url, const long http_status_code) const
1400 if ( level <= Loglevel )
1403 msg << "Problem while trying to updating service. Requested URL: " << url << " Error Code from Server: " << http_status_code << endl;
1404 log_error(msg.str());
1409 * Hostname is invalid, contains no or only one domain part.
1410 * @param hostname The full qualified host name.
1412 void Logger::print_invalid_hostname(const string& hostname)
1415 if ( (level <= Loglevel) || ((level <= ExternalWarningLevel) && (!ExternalWarningLog.empty())) )
1418 msg << "The configured hostname: " << hostname << " is invalid. Please add the corresponding domain part." << endl;
1419 log_warning(msg.str(),level);
1425 * An IP in a private range was detected
1426 * @param ip The private IP
1428 void Logger::print_ip_is_local(const string& ip)
1431 if ( (level <= Loglevel) || ((level <= ExternalWarningLevel) && (!ExternalWarningLog.empty())) )
1434 msg << "The detected IP is within a private IP range: " << ip << endl;
1435 log_warning(msg.str(),level);
1441 * Regex is matching in string
1442 * @param regex The regex pattern
1443 * @param matching_string The string
1445 void Logger::print_regex_match(const string& regex, const string& matching_string) const
1448 if ( level <= Loglevel )
1451 msg << "Regex: " << regex << " is matching in: " << matching_string << endl;
1452 log_notice(msg.str());
1458 * Regex is not matching
1459 * @param regex Regex
1460 * @param not_matching_string String
1462 void Logger::print_no_regex_match(const string& regex, const string& not_matching_string)
1465 if ( (level <= Loglevel) || ((level <= ExternalWarningLevel) && (!ExternalWarningLog.empty())) )
1468 msg << "Regex: " << regex << " is not matching in: " << not_matching_string << endl;
1469 log_warning(msg.str(),level);
1475 * Could not parse gnudip initial reply.
1476 * @param curl_data The data received from gnudip server which should contain salt, time and sign.
1478 void Logger::print_could_not_parse_received_data(const string& curl_data) const
1481 if ( (level <= Loglevel) )
1484 msg << "Could not parse salt, time and sign from initial gnudip server reply: " << curl_data << endl;
1485 log_error(msg.str());
1491 * Gnudip salt, time and sign could not be got from map
1493 void Logger::print_could_not_get_initial_gnudip_data() const
1496 if ( (level <= Loglevel) )
1498 log_error("Could not get salt, time and sign from map.");
1505 * Gnudip protocol requires explicit declaration of a servername.
1507 void Logger::print_gnudip_requires_servername()
1510 if ( (level <= Loglevel) || ((level <= ExternalWarningLevel) && (!ExternalWarningLog.empty())) )
1512 log_warning("Gnudip requires explicit definition of servername via config!",level);
1518 * An exception occured while computing the md5 sum.
1519 * @param what The exception occured.
1521 void Logger::print_exception_md5_sum(const string& what) const
1524 if ( level <= Loglevel )
1527 msg << "An exception occured while computing a md5 sum: " << what << endl;
1528 log_error(msg.str());
1534 * An network exception occured.
1535 * @param what The exception occured.
1537 void Logger::print_network_error(const string& what) const
1540 if ( level <= Loglevel )
1543 msg << "An netowrk exception occured: " << what << endl;
1544 log_error(msg.str());
1550 * An undefined protocol error occured.
1551 * @param protocol The protocol
1552 * @param error The error
1554 void Logger::print_undefined_protocol_error(const string& protocol, const string& error) const
1557 if ( level <= Loglevel )
1560 msg << "An undefined protocol error occured. Protocol: " << protocol << " Error: " << error << endl;
1561 log_error(msg.str());
1566 * Error while trying to log through external program.
1567 * @param external_prog The external program called.
1569 void Logger::print_error_external_logging(const string& external_prog) const
1572 if ( level <= Loglevel )
1575 msg << "Error while trying to log through external program: " << external_prog << endl;
1576 log_notice(msg.str());
1582 * Error while parsing config file.
1583 * @param error Error occured.
1584 * @param config_file Config file.
1586 void Logger::print_error_parsing_config_file(const string& filename, const string& error) const
1589 if ( level <= Loglevel )
1592 msg << "Error while parsing config file: " << filename << " Error: " << error << endl;
1593 log_notice(msg.str());
1599 * Error while parsing cmd option
1600 * @param error Error
1602 void Logger::print_error_parsing_cmd(const string& error) const
1605 if ( level <= Loglevel )
1608 msg << "Error while parsing cmd options: " << error << endl;
1609 log_error(msg.str());
1615 * The webcheck interval was exceeded, so webcheck not allowed.
1616 * @param last_webcheck Time of last webcheck.
1617 * @param webcheck_interval Webcheck interval time.
1618 * @param current_time Current system time.
1620 void Logger::print_webcheck_exceed_interval( const time_t last_webcheck, const int webcheck_interval, const time_t current_time ) const
1623 if ( level <= Loglevel )
1626 msg << "Exceeding webcheck interval: LastWebcheck " << last_webcheck << " + WebcheckInterval(sec) " << webcheck_interval << " >= CurrentTime " << current_time << endl;
1627 log_notice(msg.str());
1633 * Checking if hosts needs update.
1634 * @param hostname Hostname
1635 * @param current_time Current time
1636 * @param lastupdated Last updated
1638 void Logger::print_check_service_update(const string& hostname, const time_t current_time, const time_t lastupdated) const
1641 if ( level <= Loglevel )
1644 msg << "Checking if host: " << hostname << " needs update. Current time: " << current_time << " Last updated: " << lastupdated << endl;
1645 log_notice(msg.str());
1652 * @param hostname Hostname
1653 * @param ip_dns_recheck DNS recheck IP
1654 * @param ip_last_update IP set in last update
1655 * @param ip_host Hosts' IP
1657 void Logger::print_cached_dns_entry(const string& hostname, const string& ip_dns_recheck, const string& ip_last_update, const string& ip_host) const
1660 if ( level <= Loglevel )
1663 msg << "Cached DNS record for host <" << hostname << "> : " << ip_dns_recheck << " Last updated IP: " << ip_last_update << " Hosts IP: " << ip_host << endl;
1664 log_notice(msg.str());
1671 * @param hostname Hostname
1672 * @param ip_dns_recheck Cached DNS entry
1673 * @param ip_last_update IP set in last update
1674 * @param ip_host Hosts IP
1675 * @param lastupdated Lastupdated
1677 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{
1679 if ( level <= Loglevel )
1682 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;
1683 log_notice(msg.str());
1690 * @param hostname Hostname
1691 * @param ip_dns_recheck Cached DNS entry
1692 * @param ip_last_update IP set in last update
1693 * @param ip_host Hosts IP
1694 * @param lastupdated Last updated
1695 * @param dns_cache_ttl DNS cache ttl
1696 * @param current_time Current time
1698 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
1701 if ( level <= Loglevel )
1704 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;
1705 log_notice(msg.str());
1712 * @param hostname Hostname
1713 * @param ip_dns_recheck Cached DNS entry
1714 * @param ip_last_update IP set in last update
1715 * @param ip_host Hosts IP
1716 * @param lastupdated Last updated
1717 * @param dns_cache_ttl DNS cache ttl
1718 * @param current_time Current time
1720 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
1723 if ( level <= Loglevel )
1726 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;
1727 log_notice(msg.str());
1734 * @param hostname Hostname
1735 * @param ip_dns_recheck Cached DNS entry
1736 * @param ip_last_update IP set in last update
1737 * @param ip_host Hosts IP
1738 * @param lastupdated Last updated
1740 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
1743 if ( level <= Loglevel )
1746 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;
1747 log_notice(msg.str());
1753 * Error while trying to get local wan interface IP address through getifaddrs.
1754 * @param error The system call which raised the error.
1755 * @param error The error set by getifaddrs.
1757 void Logger::print_error_getting_local_wan_ip(const std::string& system_call, const std::string& error) const
1760 if ( level <= Loglevel )
1763 msg << "Error while trying to get local wan interface IP address through '" << system_call << "': " << error << endl;
1764 log_error(msg.str());
1770 * Could not get IP address of local wan interface.
1772 void Logger::print_no_wan_ip() const
1775 if ( level <= Loglevel )
1778 msg << "Could not get IP address of local wan interface." << endl;
1779 log_error(msg.str());
1785 * Invalid service config was detected.
1787 void Logger::print_invalid_service_config() const
1790 if ( level <= Loglevel )
1792 log_error("Ignoring invalid service. Please check.\n");
1798 * Print simple message.
1800 void Logger::print_msg( const string& msg ) const
1803 if ( level <= Loglevel )