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