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