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