7b4fd582782ba5a6803a9557139a3bdb461c265f
[bpdyndnsd] / src / logger.cpp
1 /** @file
2  * @brief Logger class implementation. This class implements the Logging facility.
3  *
4  *
5  *
6  * @copyright Intra2net AG
7  * @license GPLv2
8 */
9
10
11 #include "logger.hpp"
12
13 #include <iostream>
14 #include <syslog.h>
15 #include <sstream>
16
17 #include <boost/foreach.hpp>
18
19 #define VERSION     0
20 #define REVISION    1
21 #define RELEASE     0
22
23 namespace po = boost::program_options;
24
25 typedef boost::shared_ptr<boost::program_options::options_description> Options_descriptionPtr;
26
27 using namespace std;
28
29 /**
30  * Default Constructor
31  */
32 Logger::Logger()
33     : Loglevel(0)
34     , Syslog(false)
35     , ExternalWarningLevel(0)
36     , ExternalLogOnlyOnce(false)
37 {
38     set_log_facility(Loglevel,Syslog,ExternalWarningLog,ExternalWarningLevel,ExternalLogOnlyOnce);
39 }
40
41
42 /**
43  * Default Destructor
44  */
45 Logger::~Logger()
46 {
47 }
48
49
50 /**
51  * Decides if a external log message can be send.
52  * @param msg The message to log.
53  */
54 bool Logger::is_allowed_to_send( const string& msg ) const
55 {
56     if ( (ExternalLogOnlyOnce) && (ExternalSendMessages.find(msg) != ExternalSendMessages.end()) )
57         return false;
58     return true;
59 }
60
61
62 /**
63  * Clears the external send messages set.
64  */
65 void Logger::clear_external_send_messages()
66 {
67     ExternalSendMessages.clear();
68 }
69
70
71 /**
72  * Decides if Logging through syslog if enabled or through std.
73  * @param msg The message to log.
74  */
75 void Logger::log_notice(const string& msg) const
76 {
77     if ( Syslog )
78         syslog(LOG_NOTICE,msg.c_str());
79     else
80         cout << msg << endl;;
81 }
82
83
84 /**
85  * Decides if Logging through syslog if enabled or through std.
86  * @param msg The message to log.
87  */
88 void Logger::log_warning(const string& msg, int level)
89 {
90     if ( Syslog )
91         syslog(LOG_WARNING,msg.c_str());
92     else
93         cout << msg << endl;
94
95     if ( (level <= ExternalWarningLevel) && (!ExternalWarningLog.empty()) && (is_allowed_to_send(msg)) )
96     {
97         string message = msg;
98         // Remove endline from msg.
99         if (!message.empty() && message[message.length()-1] == '\n')
100             message.erase(message.length()-1);  /*lint !e534 */
101
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);
109         else
110             ExternalSendMessages.insert(msg);   /*lint !e534 */
111     }
112 }
113
114
115 /**
116  * Decides if Logging through syslog if enabled or through std.
117  * @param msg The message to log.
118  */
119 void Logger::log_error(const string& msg) const
120 {
121     if ( Syslog )
122         syslog(LOG_ERR,msg.c_str());
123     else
124         cerr << msg << endl;
125 }
126
127
128 /**
129  * Setter for member Loglevel.
130  * @param _loglevel Value to set Loglevel to.
131  */
132 void Logger::set_external_log_only_once( const bool _external_log_only_once )
133 {
134     ExternalLogOnlyOnce = _external_log_only_once;
135 }
136
137
138 /**
139  * Setter for member Loglevel.
140  * @param _loglevel Value to set Loglevel to.
141  */
142 void Logger::set_loglevel(const int _loglevel)
143 {
144     Loglevel = _loglevel;
145 }
146
147
148 /**
149  * Getter for member Loglevel.
150  * @return Loglevel.
151  */
152 int Logger::get_loglevel() const
153 {
154     return Loglevel;
155 }
156
157
158 /**
159  * Setter for member Syslog.
160  * @param _syslog Wether to log through syslog or not.
161  */
162 void Logger::set_syslog(const bool _syslog)
163 {
164     Syslog = _syslog;
165 }
166
167
168 /**
169  * Getter for member Syslog.
170  * @return True if logging through syslog is enabled, false otherwise.
171  */
172 bool Logger::get_syslog() const
173 {
174     return Syslog;
175 }
176
177
178 /**
179  * Initialize the logging facility.
180  */
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 )
182 {
183     Loglevel = _loglevel;
184     Syslog = _syslog;
185     ExternalWarningLog = _external_error_log;
186     ExternalWarningLevel = _external_error_level;
187     ExternalLogOnlyOnce = _external_log_only_once;
188
189     if ( Syslog )
190         openlog("bpdyndnsd",LOG_PID,LOG_DAEMON);
191 }
192
193
194 /**
195  * Prints out the usage to the command line.
196  */
197 void Logger::print_usage(const Options_descriptionPtr opt_desc) const
198 {
199     int level = 0;
200     if ( level <= Loglevel )
201     {
202         ostringstream msg;
203         msg << "Usage: bpdyndnsd [Command line options]" << "\n" << endl;
204         msg << *opt_desc << endl;
205         log_notice(msg.str());
206     }
207 }
208
209
210 /**
211  * Prints out the programm name and the given version string on stdout.
212  * @param version Version string.
213  */
214 void Logger::print_version() const
215 {
216     int level = 0;
217     if ( level <= Loglevel )
218     {
219         ostringstream msg;
220         msg << "Bullet proof dynamic dns daemon.\nbpdyndnsd " << VERSION << "." << REVISION << "." << RELEASE << endl;
221         log_notice(msg.str());
222     }
223 }
224
225
226 /**
227  * Prints out the successful parsing of the command line options.
228  */
229 void Logger::print_cmd_parsed() const
230 {
231     int level = 1;
232     if ( level <= Loglevel )
233     {
234         log_notice("Command line options successfully parsed.");
235     }
236 }
237
238
239 void Logger::print_conf_files_parsed() const
240 {
241     int level = 1;
242     if ( level <= Loglevel )
243     {
244         log_notice("Config files successfully parsed.");
245     }
246 }
247
248
249 /**
250  * Prints out the successful parsing of the config files.
251  * @param config_path The specified config path.
252  */
253 void Logger::print_conf_loaded(const string& config_path) const
254 {
255     int level = 1;
256     if ( level <= Loglevel )
257     {
258         ostringstream msg;
259         msg << "Config files successfully loaded in: " << config_path << endl;
260         log_notice(msg.str());
261     }
262 }
263
264
265 /**
266  * Prints out the unsuccessful parsing of the config files.
267  * @param config_path The specified config path.
268  */
269 void Logger::print_conf_not_loaded(const string& config_path) const
270 {
271     int level = 0;
272     if ( level <= Loglevel )
273     {
274         ostringstream msg;
275         msg << "Config files couldn't be loaded in: " << config_path << endl;
276         log_error(msg.str());
277     }
278 }
279
280
281 /**
282  * A file could not be opened for reading.
283  * @param filename The filename.
284  */
285 void Logger::print_error_opening_r(const string& filename) const
286 {
287     int level = 0;
288     if ( level <= Loglevel )
289     {
290         ostringstream msg;
291         msg << "Error opening file for reading: " << filename << endl;
292         log_error(msg.str());
293     }
294 }
295
296
297 /**
298  * A file could not be opened for writing.
299  * @param filename The filename.
300  */
301 void Logger::print_error_opening_rw(const string& filename) const
302 {
303     int level = 0;
304     if ( level <= Loglevel )
305     {
306         ostringstream msg;
307         msg << "Error opening file for writing: " << filename << endl;
308         log_error(msg.str());
309     }
310 }
311
312
313 /**
314  * Desctructor of specified class was called.
315  * @param _class Name of the class.
316  */
317 void Logger::print_destructor_call(const string& _class) const
318 {
319     int level = 1;
320     if ( level <= Loglevel )
321     {
322         ostringstream msg;
323         msg << "Destructor call: " << _class << endl;
324         log_notice(msg.str());
325     }
326 }
327
328
329 /**
330  * Constructor of specified class was called.
331  * @param _class Name of the class.
332  */
333 void Logger::print_constructor_call(const string& _class) const
334 {
335     int level = 1;
336     if ( level <= Loglevel )
337     {
338         ostringstream msg;
339         msg << "Constructor call: " << _class << endl;
340         log_notice(msg.str());
341     }
342 }
343
344
345 /**
346  * Update method for specified service was called.
347  * @param service The service for which is the update running.
348  */
349 void Logger::print_update_service(const string& service) const
350 {
351     int level = 0;
352     if ( level <= Loglevel )
353     {
354         ostringstream msg;
355         msg << "Running update for service: " << service << endl;
356         log_notice(msg.str());
357     }
358 }
359
360
361 /**
362  * An unknown option on the command line was detected.
363  * @param unknown_option The unknown option.
364  */
365 void Logger::print_unknown_cmd_option(const string& unknown_option) const
366 {
367     int level = 0;
368     if ( level <= Loglevel )
369     {
370         ostringstream msg;
371         msg << "Unknown option on command line detected: " << unknown_option << endl;
372         log_error(msg.str());
373     }
374 }
375
376
377 /**
378  * An unknown protocol was specified.
379  * @param protocol The unknown protocol.
380  */
381 void Logger::print_unknown_protocol(const string& protocol) const
382 {
383     int level = 0;
384     if ( level <= Loglevel )
385     {
386         ostringstream msg;
387         msg << "Unknown protocol defined: " << protocol << endl;
388         log_error(msg.str());
389     }
390 }
391
392
393 /**
394  * Loading a service config file.
395  * @param filename The service config file.
396  */
397 void Logger::print_load_service_conf(const string& filename) const
398 {
399     int level = 1;
400     if ( level <= Loglevel )
401     {
402         ostringstream msg;
403         msg << "Loading service config file: " << filename << endl;
404         log_notice(msg.str());
405     }
406 }
407
408
409 /**
410  * Loading the main config file.
411  * @param filename The main config file.
412  */
413 void Logger::print_load_main_conf(const string& filename) const
414 {
415     int level = 1;
416     if ( level <= Loglevel )
417     {
418         ostringstream msg;
419         msg << "Loading main config file: " << filename << endl;
420         log_notice(msg.str());
421     }
422 }
423
424
425 /**
426  * There is an unknown option in a service config file.
427  * @param unknown_option The unknown option.
428  */
429 void Logger::print_unknown_service_conf_option(const string& service_conf_file, const string& unknown_option) const
430 {
431     int level = 0;
432     if ( level <= Loglevel )
433     {
434         ostringstream msg;
435         msg << "Unknown option in service config file detected: " << service_conf_file << " Unknown option: " << unknown_option << endl;
436         log_error(msg.str());
437     }
438 }
439
440
441 /**
442  * There is an unknown option in the main config file.
443  * @param unknown_option The unknown option.
444  */
445 void Logger::print_unknown_main_conf_option(const string& unknown_option) const
446 {
447     int level = 0;
448     if ( level <= Loglevel )
449     {
450         ostringstream msg;
451         msg << "Unknown option in main config file detected: " << unknown_option << endl;
452         log_error(msg.str());
453     }
454 }
455
456
457 /**
458  * The defined config path doesn't exist or is not a directory.
459  * @param config_path The defined config path.
460  */
461 void Logger::print_error_config_path(const string& config_path) const
462 {
463     int level = 0;
464     if ( level <= Loglevel )
465     {
466         ostringstream msg;
467         msg << "Config path doesn't exists or is not a diretory: " << config_path << endl;
468         log_error(msg.str());
469     }
470 }
471
472
473 /**
474  * There is a missing command line option to initialize a service object.
475  */
476 void Logger::print_missing_cmd_service_option() const
477 {
478     int level = 0;
479     if ( level <= Loglevel )
480     {
481         log_error("Missing option to initialize service. Protocol, host, login and password must be specified.");
482     }
483 }
484
485
486 /**
487  * Missing option in service config file.
488  * @param service_conf_file Service config file
489  */
490 void Logger::print_missing_service_conf_option(const string& service_conf_file) const
491 {
492     int level = 0;
493     if ( level <= Loglevel )
494     {
495         ostringstream msg;
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());
498     }
499 }
500
501
502 /**
503  * Process running as daemon.
504  * @param pid The pid of the daemon.
505  */
506 void Logger::print_runnig_as_daemon(const int pid) const
507 {
508     int level = 1;
509     if ( level <= Loglevel )
510     {
511         ostringstream msg;
512         msg << "Runnig as daemon: " << pid << endl;
513         log_notice(msg.str());
514     }
515 }
516
517
518 /**
519  * Prints out the daemon mode.
520  * @param daemon_mode The daemon mode.
521  */
522 void Logger::print_daemon_mode(const bool daemon_mode) const
523 {
524     int level = 1;
525     if ( level <= Loglevel )
526     {
527         string mode = "disabled";
528         if (daemon_mode == true)
529             mode = "enabled";
530         ostringstream msg;
531         msg << "Daemon mode is " << mode << "." << endl;
532         log_notice(msg.str());
533     }
534 }
535
536
537 /**
538  * There was an error while trying to fork.
539  */
540 void Logger::print_error_fork() const
541 {
542     int level = 0;
543     if ( level <= Loglevel )
544     {
545         log_error("Error while trying to fork.");
546     }
547 }
548
549
550 /**
551  * A pid in the pidfile was found.
552  * @param pid The pid found in the pidfile.
553  */
554 void Logger::print_pid_found(const int pid) const
555 {
556     int level = 1;
557     if ( level <= Loglevel )
558     {
559         ostringstream msg;
560         msg << "Pidfile found: " << pid << ". Checking if process is still runnig..." << endl;
561         log_notice(msg.str());
562     }
563 }
564
565
566 /**
567  * Another process is already running.
568  * @param pid The pid of the other process.
569  */
570 void Logger::print_process_already_running(const int pid) const
571 {
572     int level = 0;
573     if ( level <= Loglevel )
574     {
575         ostringstream msg;
576         msg << "Another bpdyndnsd process with PID " << pid << " is already running!" << endl;
577         log_error(msg.str());
578     }
579 }
580
581
582 /**
583  * SIGTERM caught.
584  */
585 void Logger::print_caught_sigterm() const
586 {
587     int level = 0;
588     if ( level <= Loglevel )
589     {
590         log_notice("Caught SIGTERM. Exiting...");
591     }
592 }
593
594
595 /**
596  * SIGUSR1 caught.
597  */
598 void Logger::print_caught_siguser1() const
599 {
600     int level = 0;
601     if ( level <= Loglevel )
602     {
603         log_notice("Caught SIGUSR1. Switching to offline mode...");
604     }
605 }
606
607
608 /**
609  * SIGHUP caught.
610  */
611 void Logger::print_caught_sighup() const
612 {
613     int level = 0;
614     if ( level <= Loglevel )
615     {
616         log_notice("Caught SIGHUP. Reloading config...");
617     }
618 }
619
620
621 /**
622  * SIGUSR2 caught.
623  */
624 void Logger::print_caught_siguser2() const
625 {
626     int level = 0;
627     if ( level <= Loglevel )
628     {
629         log_notice("Caught SIGUSR2. Switching to online mode...");
630     }
631 }
632
633
634 /**
635  * SIGRTMIN caught.
636  */
637 void Logger::print_caught_sigrtmin() const
638 {
639     int level = 0;
640     if ( level <= Loglevel )
641     {
642         log_notice("Caught SIGRTMIN. Switching to online mode with webcheck enabled...");
643     }
644 }
645
646
647 /**
648  * Error while setting signal handler.
649  */
650 void Logger::print_error_setting_signal(const string& signal) const
651 {
652     int level = 0;
653     if ( level <= Loglevel )
654     {
655         ostringstream msg;
656         msg << "Error while setting signal handler for: " << signal << endl;
657         log_error(msg.str());
658     }
659 }
660
661
662 /**
663  * Error while setting signal handler.
664  */
665 void Logger::print_init_log_facility() const
666 {
667     int level = 1;
668     if ( level <= Loglevel )
669     {
670         ostringstream msg;
671         msg << "Initialized logging facility." << " Loglevel: " << Loglevel << " Syslog: " << Syslog << " ExternalLogOnlyOnce: " << ExternalLogOnlyOnce << endl;
672         log_notice(msg.str());
673     }
674 }
675
676
677 /**
678  * Be verbose. Currently we are in offline mode.
679  */
680 void Logger::print_offline_mode() const
681 {
682     int level = 1;
683     if ( level <= Loglevel )
684     {
685         log_notice("Offline mode...");
686     }
687 }
688
689
690 /**
691  * Objects successfully serialized.
692  */
693 void Logger::print_serialized_objects_success() const
694 {
695     int level = 1;
696     if ( level <= Loglevel )
697     {
698         log_notice("Serialized objects successfully.");
699     }
700 }
701
702
703 /**
704  * Objects successfully de-serialized.
705  */
706 void Logger::print_deserialized_objects_success() const
707 {
708     int level = 1;
709     if ( level <= Loglevel )
710     {
711         log_notice("De-serialized objects successfully.");
712     }
713 }
714
715
716 /**
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.
725  */
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
727 {
728     int level = 1;
729     if ( level <= Loglevel )
730     {
731         ostringstream msg;
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)
742         {
743             msg << "\t" << "Lastupdated:      " << update_time << endl;
744         }
745         log_notice(msg.str());
746     }
747 }
748
749
750 /**
751  * Caught exception while serialize.
752  * @param exception Exception message.
753  */
754 void Logger::print_exception_serialize(const string& errMsg) const
755 {
756     int level = 0;
757     if ( level <= Loglevel )
758     {
759         ostringstream msg;
760         msg << "Error while trying to serialize Serviceholder object: " << errMsg << endl;
761         log_error(msg.str());
762     }
763 }
764
765
766 /**
767  * Caught exception while de-serialize.
768  * @param exception Exception message.
769  */
770 void Logger::print_exception_deserialize(const string& errMsg) const
771 {
772     int level = 0;
773     if ( level <= Loglevel )
774     {
775         ostringstream msg;
776         msg << "Error while trying to de-serialize Serviceholder object: " << errMsg << endl;
777         log_error(msg.str());
778     }
779 }
780
781
782 /**
783  * Child couldn't be killed by parent.
784  * @param pid Pid of the child.
785  */
786 void Logger::print_error_kill_child(const int pid) const
787 {
788     int level = 0;
789     if ( level <= Loglevel )
790     {
791         ostringstream msg;
792         msg << "Could not kill child process with PID: " << pid << endl;
793         log_error(msg.str());
794     }
795 }
796
797
798 /**
799  * Child was killed by parent because of error.
800  * @param pid The pid (child) killed.
801  */
802 void Logger::print_child_killed(const int pid) const
803 {
804     int level = 1;
805     if ( level <= Loglevel )
806     {
807         ostringstream msg;
808         msg << "Killed child process with PID: " << pid << endl;
809         log_notice(msg.str());
810     }
811 }
812
813
814 /**
815  * There is no object file.
816  * @param object_file The object file.
817  */
818 void Logger::print_no_object_file(const string& object_file)
819 {
820     int level = 1;
821     if ( (level <= Loglevel) || ((level <= ExternalWarningLevel) && (!ExternalWarningLog.empty())) )
822     {
823         ostringstream msg;
824         msg << "There is no object file: " << object_file << ". Continue without recovering state from old services!" << endl;
825         log_warning(msg.str(),level);
826     }
827 }
828
829
830 /**
831  * Prints out the given hostname
832  * @param hostname Hostname as string.
833  */
834 void Logger::print_hostname(const string& hostname) const
835 {
836     int level = 1;
837     if ( level <= Loglevel )
838     {
839         ostringstream msg;
840         msg << "Detected following hostname of localhost: " << hostname << endl;
841         log_notice(msg.str());
842     }
843 }
844
845
846 /**
847  * Prints out the detected own ipv4 address
848  * @param ip_addr String representation of the detected ip.
849  */
850 void Logger::print_own_ipv4(const string& ip_addr_v4, const string& hostname) const
851 {
852     int level = 1;
853     if ( level <= Loglevel )
854     {
855         ostringstream msg;
856         msg << "Detected following IPv4-Address of host: " << hostname << " : " << ip_addr_v4 << endl;
857         log_notice(msg.str());
858     }
859 }
860
861
862 /**
863  * Prints out the detected own ipv5 address
864  * @param ip_addr String representation of the detected ip.
865  */
866 void Logger::print_own_ipv6(const string& ip_addr_v6, const string& hostname) const
867 {
868     int level = 1;
869     if ( level <= Loglevel )
870     {
871         ostringstream msg;
872         msg << "Detected following IPv6-Address of host: " << hostname << " : " << ip_addr_v6 << endl;
873         log_notice(msg.str());
874     }
875 }
876
877
878 /**
879  * Exception while trying to resolve hostname to ip.
880  * @param exception The exception caught.
881  * @param hostname The hostname.
882  */
883 void Logger::print_error_hostname_to_ip(const string& errMsg, const string& hostname) const
884 {
885     int level = 0;
886     if ( level <= Loglevel )
887     {
888         ostringstream msg;
889         msg << "Could not resolve the hostname: " << hostname << " to an IP-Address: " << errMsg << endl;
890         log_error(msg.str());
891     }
892 }
893
894
895 /**
896  * The update of the given service was successful.
897  * @param service The service.
898  */
899 void Logger::print_update_service_successful(const string& service) const
900 {
901     int level = 0;
902     if ( level <= Loglevel )
903     {
904         ostringstream msg;
905         msg << "Updated service successful: " << service << endl;
906         log_notice(msg.str());
907     }
908 }
909
910
911 /**
912  * No ip could be determined through webcheck
913  */
914 void Logger::print_webcheck_no_ip()
915 {
916     int level = 0;
917     if ( (level <= Loglevel) || ((level <= ExternalWarningLevel) && (!ExternalWarningLog.empty())) )
918     {
919         log_warning("IP-Address of this host could not be determined through any configured webcheck url.",level);
920     }
921 }
922
923
924 /**
925  * Connection problem while trying to get ip through webcheck url
926  * @param curl_err_buff Curl error message
927  * @param url the url
928  */
929 void Logger::print_webcheck_url_connection_problem(const char * curl_err_buff, const string& url)
930 {
931     int level = 1;
932     if ( (level <= Loglevel) || ((level <= ExternalWarningLevel) && (!ExternalWarningLog.empty())) )
933     {
934         ostringstream msg;
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);
937     }
938 }
939
940
941 /**
942  * Prints out curl error.
943  * @param curl_err_buff Curl error message.
944  * @param url URL
945  */
946 void Logger::print_webcheck_error(const char * curl_err_buff, const string& url) const
947 {
948     int level = 0;
949     if ( level <= Loglevel )
950     {
951         ostringstream msg;
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());
954     }
955 }
956
957
958 /**
959  * Prints out the received data through curl.
960  * @param curl_data Data string
961  */
962 void Logger::print_received_curl_data(const string& curl_data) const
963 {
964     int level = 1;
965     if ( level <= Loglevel )
966     {
967         ostringstream msg;
968         msg << "Received CURL data: " << curl_data << endl;
969         log_notice(msg.str());
970     }
971 }
972
973
974 /**
975  * IP was foudn through regex
976  * @param ip The IP found.
977  */
978 void Logger::print_regex_found_ip(const string& ip) const
979 {
980     int level = 1;
981     if ( level <= Loglevel )
982     {
983         ostringstream msg;
984         msg << "Found IP-Address via regex: " << ip << endl;
985         log_notice(msg.str());
986     }
987 }
988
989
990 /**
991  * No IP was found through regex.
992  * @param data The data string which should contain a valid IP.s
993  */
994 void Logger::print_regex_ip_not_found(const string& data)
995 {
996     int level = 1;
997     if ( (level <= Loglevel) || ((level <= ExternalWarningLevel) && (!ExternalWarningLog.empty())) )
998     {
999         ostringstream msg;
1000         msg << "Could not extract an IP-Address via regex from following data:\n" << data << endl;
1001         log_warning(msg.str(),level);
1002     }
1003 }
1004
1005
1006 /**
1007  * Detected multiple occurrences of the same option.
1008  * @param message Error message.
1009  */
1010 void Logger::print_multiple_cmd_option(const string& message) const
1011 {
1012     int level = 0;
1013     if ( level <= Loglevel )
1014     {
1015         ostringstream msg;
1016         msg << "The same option is only allowed once: " << message << endl;
1017         log_error(msg.str());
1018     }
1019 }
1020
1021
1022 /**
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.
1028  */
1029 void Logger::print_update_not_allowed(const time_t current_time, const time_t old_time, const int MaxUpdatesWithinInterval, const string& service)
1030 {
1031     int level = 1;
1032     if ( (level <= Loglevel) || ((level <= ExternalWarningLevel) && (!ExternalWarningLog.empty())) )
1033     {
1034         ostringstream msg;
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);
1037     }
1038 }
1039
1040
1041 /**
1042  * Failure while running update for service.
1043  * @param service Services' name.
1044  */
1045 void Logger::print_update_service_failure(const string& service)
1046 {
1047     int level = 0;
1048     if ( (level <= Loglevel) || ((level <= ExternalWarningLevel) && (!ExternalWarningLog.empty())) )
1049     {
1050         ostringstream msg;
1051         msg << "Could not update service: " << service << endl;
1052         log_warning(msg.str(),level);
1053     }
1054 }
1055
1056
1057 /**
1058  * Starting shutdown
1059  */
1060 void Logger::print_starting_shutdown() const
1061 {
1062     int level = 0;
1063     if ( level <= Loglevel )
1064     {
1065         log_notice("Shutting down ...");
1066     }
1067 }
1068
1069
1070 /**
1071  * Shutdown complete
1072  */
1073 void Logger::print_shutdown_succeeded() const
1074 {
1075     int level = 0;
1076     if ( level <= Loglevel )
1077     {
1078         log_notice("Shutting down complete ...");
1079     }
1080 }
1081
1082
1083 /**
1084  * Shutdown parent succeeded
1085  */
1086 void Logger::print_shutdown_parent_succeeded() const
1087 {
1088     int level = 0;
1089     if ( level <= Loglevel )
1090     {
1091         log_notice("Shutting down parent process completed ...");
1092     }
1093 }
1094
1095
1096 /**
1097  * Starting shutdown parent
1098  */
1099 void Logger::print_starting_shutdown_parent() const
1100 {
1101     int level = 0;
1102     if ( level <= Loglevel )
1103     {
1104         log_notice("Shutting down parent process ...");
1105     }
1106 }
1107
1108
1109 /**
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
1115  */
1116 void Logger::print_recheck_dns_entry(const string& hostname, const int lastupdated, const int dns_cache_ttl, const int current_time) const
1117 {
1118     int level = 1;
1119     if ( level <= Loglevel )
1120     {
1121         ostringstream msg;
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());
1124     }
1125 }
1126
1127
1128 /**
1129  * Missing proxy option on command line.
1130  */
1131 void Logger::print_missing_cmd_proxy_option() const
1132 {
1133     int level = 0;
1134     if ( level <= Loglevel )
1135     {
1136         log_error("Missing option to initialize proxy. http_proxy and http_proxy_port must be specified.");
1137     }
1138 }
1139
1140
1141 /**
1142  * Multiple option in service config file.
1143  * @param service_conf_file Service config file
1144  * @param message Multiple option text
1145  */
1146 void Logger::print_multiple_service_conf_option(const string& service_conf_file, const string& message) const
1147 {
1148     int level = 0;
1149     if ( level <= Loglevel )
1150     {
1151         ostringstream msg;
1152         msg << "Multiple occurrences of the same option in service config file detected: " << service_conf_file << " " << message << endl;
1153         log_error(msg.str());
1154     }
1155 }
1156
1157
1158 /**
1159  * Multiple option in main config file.
1160  * @param service_conf_file Service config file
1161  * @param message Multiple option text
1162  */
1163 void Logger::print_multiple_main_conf_option(const string& main_conf_file, const string& message) const
1164 {
1165     int level = 0;
1166     if ( level <= Loglevel )
1167     {
1168         ostringstream msg;
1169         msg << "Multiple occurrences of the same option in main config file detected: " << main_conf_file << " " << message << endl;
1170         log_error(msg.str());
1171     }
1172 }
1173
1174
1175 /**
1176  * Missing proxy option in main config file.
1177  * @param main_conf_filename The concerning config file.
1178  */
1179 void Logger::print_missing_conf_proxy_option(const string& main_conf_filename) const
1180 {
1181     int level = 0;
1182     if ( level <= Loglevel )
1183     {
1184         ostringstream msg;
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());
1187     }
1188 }
1189
1190
1191 /**
1192  * There is no domain part in the given hostname
1193  * @param hostname The hostname with no domain part in it.
1194  */
1195 void Logger::print_no_domain_part(const string& hostname) const
1196 {
1197     int level = 0;
1198     if ( level <= Loglevel )
1199     {
1200         ostringstream msg;
1201         msg << "There is no domain part in the given hostname: " << hostname << endl;
1202         log_notice(msg.str());
1203     }
1204 }
1205
1206
1207 /**
1208  * Service is not initialized properly.
1209  * @param service The service.
1210  */
1211 void Logger::print_httphelper_not_initialized() const
1212 {
1213     int level = 0;
1214     if ( level <= Loglevel )
1215     {
1216         log_error("HTTP-Helper is not initialized properly.");
1217     }
1218 }
1219
1220
1221 /**
1222  * An curl error occured.
1223  * @param msg The error message
1224  * @param curl_err_code The resulting curl error code
1225  */
1226 void Logger::print_curl_error_init(const std::string& err_msg, const CURLcode curl_err_code) const
1227 {
1228     string curl_err = "";
1229
1230     if ( curl_err_code == CURLE_FAILED_INIT )
1231         curl_err = "CURLE_FAILED_INIT";
1232     else
1233         curl_err = "UNKNOWN";
1234
1235     int level = 0;
1236     if ( (level <= Loglevel) )
1237     {
1238         ostringstream msg;
1239         msg << "Curl error: " << err_msg << " Curl error code: " << curl_err_code << " " << curl_err << endl; /*lint !e641 */
1240         log_error(msg.str());
1241     }
1242 }
1243
1244
1245 /**
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
1249  */
1250 void Logger::print_curl_error(const string& url, const CURLcode curl_err_code) const
1251 {
1252     string curl_err = "";
1253
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";
1260     else
1261         curl_err = "UNKNOWN";
1262
1263     int level = 0;
1264     if ( (level <= Loglevel) )
1265     {
1266         ostringstream msg;
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());
1269     }
1270 }
1271
1272
1273 /**
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
1278  */
1279 void Logger::print_curl_error(const string& url, const CURLcode curl_err_code, const char * curl_err_buff) const
1280 {
1281     string curl_err = "";
1282
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";
1289     else
1290         curl_err = "UNKNOWN";
1291
1292     int level = 0;
1293     if ( (level <= Loglevel) )
1294     {
1295         ostringstream msg;
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());
1298     }
1299 }
1300
1301
1302 /**
1303  * Prints out the data received by curl operation
1304  * @param CurlWritedataBuff
1305  */
1306 void Logger::print_curl_data(const string& curl_writedata_buff) const
1307 {
1308     int level = 1;
1309     if ( level <= Loglevel )
1310     {
1311         ostringstream msg;
1312         msg << "Data received by curl: " << curl_writedata_buff << endl;
1313         log_notice(msg.str());
1314     }
1315 }
1316
1317
1318 /**
1319  * Not authorized to perform requested update operation
1320  * @param service The requested service.
1321  * @param username Username
1322  * @param password Password
1323  */
1324 void Logger::print_service_not_authorized(const string& service, const string& username, const string& password) const
1325 {
1326     int level = 0;
1327     if ( level <= Loglevel )
1328     {
1329         ostringstream msg;
1330         msg << "Not authorized to perform update operation on service: " << service << " Please check username and password: " << username << ":" << password << endl;
1331         log_notice(msg.str());
1332     }
1333 }
1334
1335
1336 /**
1337  * Prints out the http status code
1338  * @param url Url
1339  * @param output HTTP status code
1340  */
1341 void Logger::print_http_status_code(const string& url, const long http_code) const
1342 {
1343     int level = 1;
1344     if ( level <= Loglevel )
1345     {
1346         ostringstream msg;
1347         msg << "Requested URL: " << url << " Received HTTP status code: " << http_code << endl;
1348         log_notice(msg.str());
1349     }
1350 }
1351
1352
1353 /**
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
1357  */
1358 void Logger::print_update_failure(const string& url, const string& curl_data) const
1359 {
1360     int level = 0;
1361     if ( (level <= Loglevel) )
1362     {
1363         ostringstream msg;
1364         msg << "Problem while trying to updating service. Requested URL: " << url << " Error Code from Server: " << curl_data << endl;
1365         log_error(msg.str());
1366     }
1367 }
1368
1369
1370 /**
1371  * Generic failure while trying to update service
1372  * @param url The requested URL
1373  * @param http_status_code The received http status code
1374  */
1375 void Logger::print_update_failure(const string& url, const long http_status_code) const
1376 {
1377     int level = 0;
1378     if ( level <= Loglevel )
1379     {
1380         ostringstream msg;
1381         msg << "Problem while trying to updating service. Requested URL: " << url << " Error Code from Server: " << http_status_code << endl;
1382         log_error(msg.str());
1383     }
1384 }
1385
1386 /**
1387  * Hostname is invalid, contains no or only one domain part.
1388  * @param hostname The full qualified host name.
1389  */
1390 void Logger::print_invalid_hostname(const string& hostname)
1391 {
1392     int level = 0;
1393     if ( (level <= Loglevel) || ((level <= ExternalWarningLevel) && (!ExternalWarningLog.empty())) )
1394     {
1395         ostringstream msg;
1396         msg << "The configured hostname: " << hostname << " is invalid. Please add the corresponding domain part." << endl;
1397         log_warning(msg.str(),level);
1398     }
1399 }
1400
1401
1402 /**
1403  * An IP in a private range was detected
1404  * @param ip The private IP
1405  */
1406 void Logger::print_ip_is_local(const string& ip)
1407 {
1408     int level = 1;
1409     if ( (level <= Loglevel) || ((level <= ExternalWarningLevel) && (!ExternalWarningLog.empty())) )
1410     {
1411         ostringstream msg;
1412         msg << "The detected IP is within a private IP range: " << ip << endl;
1413         log_warning(msg.str(),level);
1414     }
1415 }
1416
1417
1418 /**
1419  * Regex is matching in string
1420  * @param regex The regex pattern
1421  * @param matching_string The string
1422  */
1423 void Logger::print_regex_match(const string& regex, const string& matching_string) const
1424 {
1425     int level = 1;
1426     if ( level <= Loglevel )
1427     {
1428         ostringstream msg;
1429         msg << "Regex: " << regex << " is matching in: " << matching_string << endl;
1430         log_notice(msg.str());
1431     }
1432 }
1433
1434
1435 /**
1436  * Regex is not matching
1437  * @param regex Regex
1438  * @param not_matching_string String
1439  */
1440 void Logger::print_no_regex_match(const string& regex, const string& not_matching_string)
1441 {
1442     int level = 1;
1443     if ( (level <= Loglevel) || ((level <= ExternalWarningLevel) && (!ExternalWarningLog.empty())) )
1444     {
1445         ostringstream msg;
1446         msg << "Regex: " << regex << " is not matching in: " << not_matching_string << endl;
1447         log_warning(msg.str(),level);
1448     }
1449 }
1450
1451
1452 /**
1453  * Could not parse gnudip initial reply.
1454  * @param curl_data The data received from gnudip server which should contain salt, time and sign.
1455  */
1456 void Logger::print_could_not_parse_received_data(const string& curl_data) const
1457 {
1458     int level = 0;
1459     if ( (level <= Loglevel) )
1460     {
1461         ostringstream msg;
1462         msg << "Could not parse salt, time and sign from initial gnudip server reply: " << curl_data << endl;
1463         log_error(msg.str());
1464     }
1465 }
1466
1467
1468 /**
1469  * Gnudip salt, time and sign could not be got from map
1470  */
1471 void Logger::print_could_not_get_initial_gnudip_data() const
1472 {
1473     int level = 0;
1474     if ( (level <= Loglevel) )
1475     {
1476         log_error("Could not get salt, time and sign from map.");
1477     }
1478 }
1479
1480
1481
1482 /**
1483  * Gnudip protocol requires explicit declaration of a servername.
1484  */
1485 void Logger::print_gnudip_requires_servername()
1486 {
1487     int level = 0;
1488     if ( (level <= Loglevel) || ((level <= ExternalWarningLevel) && (!ExternalWarningLog.empty())) )
1489     {
1490         log_warning("Gnudip requires explicit definition of servername via config!",level);
1491     }
1492 }
1493
1494
1495 /**
1496  * An exception occured while computing the md5 sum.
1497  * @param what The exception occured.
1498  */
1499 void Logger::print_exception_md5_sum(const string& what) const
1500 {
1501     int level = 0;
1502     if ( level <= Loglevel )
1503     {
1504         ostringstream msg;
1505         msg << "An exception occured while computing a md5 sum: " << what << endl;
1506         log_error(msg.str());
1507     }
1508 }
1509
1510
1511 /**
1512  * An network exception occured.
1513  * @param what The exception occured.
1514  */
1515 void Logger::print_network_error(const string& what) const
1516 {
1517     int level = 0;
1518     if ( level <= Loglevel )
1519     {
1520         ostringstream msg;
1521         msg << "An netowrk exception occured: " << what << endl;
1522         log_error(msg.str());
1523     }
1524 }
1525
1526
1527 /**
1528  * An undefined protocol error occured.
1529  * @param protocol The protocol
1530  * @param error The error
1531  */
1532 void Logger::print_undefined_protocol_error(const string& protocol, const string& error) const
1533 {
1534     int level = 0;
1535     if ( level <= Loglevel )
1536     {
1537         ostringstream msg;
1538         msg << "An undefined protocol error occured. Protocol: " << protocol << " Error: " << error << endl;
1539         log_error(msg.str());
1540     }
1541 }
1542
1543 /**
1544  * Error while trying to log through external program.
1545  * @param external_prog The external program called.
1546  */
1547 void Logger::print_error_external_logging(const string& external_prog) const
1548 {
1549     int level = 0;
1550     if ( level <= Loglevel )
1551     {
1552         ostringstream msg;
1553         msg << "Error while trying to log through external program: " << external_prog << endl;
1554         log_notice(msg.str());
1555     }
1556 }
1557
1558
1559 /**
1560  * Error while parsing config file.
1561  * @param error Error occured.
1562  * @param config_file Config file.
1563  */
1564 void Logger::print_error_parsing_config_file(const string& filename, const string& error) const
1565 {
1566     int level = 0;
1567     if ( level <= Loglevel )
1568     {
1569         ostringstream msg;
1570         msg << "Error while parsing config file: " << filename << " Error: " << error << endl;
1571         log_notice(msg.str());
1572     }
1573 }
1574
1575
1576 /**
1577  * Error while parsing cmd option
1578  * @param error Error
1579  */
1580 void Logger::print_error_parsing_cmd(const string& error) const
1581 {
1582     int level = 0;
1583     if ( level <= Loglevel )
1584     {
1585         ostringstream msg;
1586         msg << "Error while parsing cmd options: " << error << endl;
1587         log_error(msg.str());
1588     }
1589 }
1590
1591
1592 /**
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.
1597  */
1598 void Logger::print_webcheck_exceed_interval( const time_t last_webcheck, const int webcheck_interval, const time_t current_time ) const
1599 {
1600     int level = 1;
1601     if ( level <= Loglevel )
1602     {
1603         ostringstream msg;
1604         msg << "Exceeding webcheck interval: LastWebcheck " << last_webcheck << " + WebcheckInterval(sec) " << webcheck_interval << " >= CurrentTime " << current_time << endl;
1605         log_notice(msg.str());
1606     }
1607 }
1608
1609
1610 /**
1611  * Checking if hosts needs update.
1612  * @param hostname Hostname
1613  * @param current_time Current time
1614  * @param lastupdated Last updated
1615  */
1616 void Logger::print_check_service_update(const string& hostname, const time_t current_time, const time_t lastupdated) const
1617 {
1618     int level = 1;
1619     if ( level <= Loglevel )
1620     {
1621         ostringstream msg;
1622         msg << "Checking if host: " << hostname << " needs update. Current time: " << current_time << " Last updated: " << lastupdated << endl;
1623         log_notice(msg.str());
1624     }
1625 }
1626
1627
1628 /**
1629  * Cached DNS entry
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
1634  */
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
1636 {
1637     int level = 1;
1638     if ( level <= Loglevel )
1639     {
1640         ostringstream msg;
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());
1643     }
1644 }
1645
1646
1647 /**
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
1652  */
1653 void Logger::print_update_service_firttime(const string& hostname, const string& ip_dns_recheck, const string& ip_host) const
1654 {
1655     int level = 1;
1656     if ( level <= Loglevel )
1657     {
1658         ostringstream msg;
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());
1661     }
1662 }
1663
1664
1665 /**
1666  * Updating service
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
1672  */
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{
1674     int level = 1;
1675     if ( level <= Loglevel )
1676     {
1677         ostringstream msg;
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());
1680     }
1681 }
1682
1683
1684 /**
1685  * TTL expired
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
1693  */
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
1695 {
1696     int level = 1;
1697     if ( level <= Loglevel )
1698     {
1699         ostringstream msg;
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());
1702     }
1703 }
1704
1705
1706 /**
1707  * TTL expired
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
1715  */
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
1717 {
1718     int level = 1;
1719     if ( level <= Loglevel )
1720     {
1721         ostringstream msg;
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());
1724     }
1725 }
1726
1727
1728 /**
1729  * No update needed
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
1735  */
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
1737 {
1738     int level = 1;
1739     if ( level <= Loglevel )
1740     {
1741         ostringstream msg;
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());
1744     }
1745 }
1746
1747
1748 /**
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.
1752  */
1753 void Logger::print_error_getting_local_wan_ip(const std::string& system_call, const std::string& error) const
1754 {
1755     int level = 0;
1756     if ( level <= Loglevel )
1757     {
1758         ostringstream msg;
1759         msg << "Error while trying to get local wan interface IP address through '" << system_call << "': " << error << endl;
1760         log_error(msg.str());
1761     }
1762 }
1763
1764
1765 /**
1766  * Could not get IP address of local wan interface.
1767  */
1768 void Logger::print_no_wan_ip() const
1769 {
1770     int level = 1;
1771     if ( level <= Loglevel )
1772     {
1773         ostringstream msg;
1774         msg << "Could not get IP address of local wan interface." << endl;
1775         log_error(msg.str());
1776     }
1777 }
1778
1779
1780 /**
1781  * Invalid service config was detected.
1782  */
1783 void Logger::print_invalid_service_config() const
1784 {
1785     int level = 0;
1786     if ( level <= Loglevel )
1787     {
1788         log_error("Ignoring invalid service. Please check.\n");
1789     }
1790 }
1791
1792
1793 /**
1794  * Print simple message.
1795  */
1796 void Logger::print_msg( const string& msg ) const
1797 {
1798     int level = 0;
1799     if ( level <= Loglevel )
1800     {
1801         log_error(msg);
1802     }
1803 }