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