Commit | Line | Data |
---|---|---|
254bbf53 BS |
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.h" | |
12 | ||
88a594e8 BS |
13 | #include <syslog.h> |
14 | #include <sstream> | |
15 | ||
3c0cd271 BS |
16 | #include <boost/foreach.hpp> |
17 | ||
8bca3c5d BS |
18 | namespace po = boost::program_options; |
19 | ||
20 | using namespace std; | |
254bbf53 BS |
21 | |
22 | /** | |
23 | * Default Constructor | |
24 | */ | |
25 | Logger::Logger() | |
8bca3c5d | 26 | : Loglevel(0) |
2e956a36 | 27 | , Syslog(false) |
254bbf53 | 28 | { |
59c8d63c | 29 | set_log_facility(Loglevel,Syslog); |
254bbf53 BS |
30 | } |
31 | ||
32 | ||
33 | /** | |
34 | * Default Destructor | |
35 | */ | |
36 | Logger::~Logger() | |
37 | { | |
254bbf53 BS |
38 | } |
39 | ||
40 | ||
41 | /** | |
59c8d63c BS |
42 | * Decides if Logging through syslog if enabled or through std. |
43 | * @param msg The message to log. | |
44 | */ | |
b38684ce | 45 | void Logger::log_notice(const string& msg) const |
59c8d63c BS |
46 | { |
47 | if ( Syslog ) | |
48 | syslog(LOG_NOTICE,msg.c_str()); | |
49 | else | |
27baf279 | 50 | cout << msg << endl;; |
59c8d63c BS |
51 | } |
52 | ||
53 | ||
54 | /** | |
55 | * Decides if Logging through syslog if enabled or through std. | |
56 | * @param msg The message to log. | |
57 | */ | |
b38684ce | 58 | void Logger::log_warning(const string& msg) const |
59c8d63c BS |
59 | { |
60 | if ( Syslog ) | |
61 | syslog(LOG_WARNING,msg.c_str()); | |
62 | else | |
27baf279 | 63 | cout << msg << endl; |
59c8d63c BS |
64 | } |
65 | ||
66 | ||
67 | /** | |
68 | * Decides if Logging through syslog if enabled or through std. | |
69 | * @param msg The message to log. | |
70 | */ | |
b38684ce | 71 | void Logger::log_error(const string& msg) const |
59c8d63c BS |
72 | { |
73 | if ( Syslog ) | |
74 | syslog(LOG_ERR,msg.c_str()); | |
75 | else | |
27baf279 | 76 | cerr << msg << endl; |
59c8d63c BS |
77 | } |
78 | ||
79 | ||
80 | /** | |
8bca3c5d BS |
81 | * Setter for member Loglevel. |
82 | * @param _loglevel Value to set Loglevel to. | |
83 | */ | |
84 | void Logger::set_loglevel(const int _loglevel) | |
85 | { | |
86 | Loglevel = _loglevel; | |
2e956a36 | 87 | cout << "Loglevel set" << endl; |
8bca3c5d BS |
88 | } |
89 | ||
90 | ||
91 | /** | |
92 | * Getter for member Loglevel. | |
93 | * @return Loglevel. | |
94 | */ | |
b38684ce | 95 | int Logger::get_loglevel() const |
8bca3c5d BS |
96 | { |
97 | return Loglevel; | |
98 | } | |
99 | ||
100 | ||
101 | /** | |
102 | * Setter for member Syslog. | |
103 | * @param _syslog Wether to log through syslog or not. | |
104 | */ | |
105 | void Logger::set_syslog(const bool _syslog) | |
106 | { | |
107 | Syslog = _syslog; | |
108 | } | |
109 | ||
110 | ||
111 | /** | |
112 | * Getter for member Syslog. | |
113 | * @return True if logging through syslog is enabled, false otherwise. | |
114 | */ | |
b38684ce | 115 | bool Logger::get_syslog() const |
8bca3c5d BS |
116 | { |
117 | return Syslog; | |
118 | } | |
119 | ||
120 | ||
121 | /** | |
122 | * Initialize the logging facility. | |
123 | */ | |
124 | void Logger::set_log_facility(const int _loglevel, const bool _syslog) | |
125 | { | |
126 | Loglevel = _loglevel; | |
127 | Syslog = _syslog; | |
128 | ||
129 | if ( Syslog ) | |
130 | openlog("bpdyndnsd",LOG_PID,LOG_DAEMON); | |
131 | } | |
132 | ||
133 | ||
134 | /** | |
254bbf53 BS |
135 | * Prints out the usage to the command line. |
136 | */ | |
b38684ce | 137 | void Logger::print_usage(const Options_descriptionPtr opt_desc) const |
254bbf53 | 138 | { |
59c8d63c BS |
139 | if ( 0 <= Loglevel ) |
140 | { | |
141 | ostringstream msg; | |
142 | msg << "Usage: bpdyndnsd [Command line options]" << "\n" << endl; | |
143 | msg << *opt_desc << endl; | |
144 | log_notice(msg.str()); | |
145 | } | |
254bbf53 BS |
146 | } |
147 | ||
148 | ||
149 | /** | |
150 | * Prints out the programm name and the given version string on stdout. | |
151 | * @param version Version string. | |
152 | */ | |
b38684ce | 153 | void Logger::print_version() const |
254bbf53 | 154 | { |
59c8d63c BS |
155 | if ( 0 <= Loglevel ) |
156 | { | |
157 | ostringstream msg; | |
158 | msg << "Bullet proof dynamic dns daemon.\nbpdyndnsd " << VERSION << "." << REVISION << "." << RELEASE << endl; | |
159 | log_notice(msg.str()); | |
160 | } | |
254bbf53 BS |
161 | } |
162 | ||
163 | ||
164 | /** | |
165 | * Prints out the successful parsing of the command line options. | |
166 | */ | |
b38684ce | 167 | void Logger::print_cmd_parsed() const |
254bbf53 | 168 | { |
59c8d63c BS |
169 | if ( 1 <= Loglevel ) |
170 | { | |
171 | ostringstream msg; | |
172 | msg << "Command line options successfully parsed." << endl; | |
173 | log_notice(msg.str()); | |
174 | } | |
254bbf53 BS |
175 | } |
176 | ||
177 | ||
b38684ce | 178 | void Logger::print_conf_files_parsed() const |
667c672c BS |
179 | { |
180 | if ( 1 <= Loglevel ) | |
181 | { | |
182 | ostringstream msg; | |
183 | msg << "Config files successfully parsed." << endl; | |
184 | log_notice(msg.str()); | |
185 | } | |
186 | } | |
187 | ||
188 | ||
254bbf53 BS |
189 | /** |
190 | * Prints out the successful parsing of the config files. | |
daf2ea82 | 191 | * @param config_path The specified config path. |
254bbf53 | 192 | */ |
b38684ce | 193 | void Logger::print_conf_loaded(const string& config_path) const |
254bbf53 | 194 | { |
59c8d63c BS |
195 | if ( 1 <= Loglevel ) |
196 | { | |
197 | ostringstream msg; | |
198 | msg << "Config files successfully loaded in: " << config_path << endl; | |
199 | log_notice(msg.str()); | |
200 | } | |
254bbf53 BS |
201 | } |
202 | ||
203 | ||
204 | /** | |
daf2ea82 BS |
205 | * Prints out the unsuccessful parsing of the config files. |
206 | * @param config_path The specified config path. | |
254bbf53 | 207 | */ |
b38684ce | 208 | void Logger::print_conf_not_loaded(const string& config_path) const |
254bbf53 | 209 | { |
59c8d63c BS |
210 | if ( 0 <= Loglevel ) |
211 | { | |
212 | ostringstream msg; | |
213 | msg << "Config files couldn't be loaded in: " << config_path << endl; | |
214 | log_error(msg.str()); | |
215 | } | |
254bbf53 BS |
216 | } |
217 | ||
218 | ||
219 | /** | |
daf2ea82 BS |
220 | * A file could not be opened for reading. |
221 | * @param filename The filename. | |
254bbf53 | 222 | */ |
b38684ce | 223 | void Logger::print_error_opening_r(const string& filename) const |
254bbf53 | 224 | { |
59c8d63c BS |
225 | if ( 0 <= Loglevel ) |
226 | { | |
227 | ostringstream msg; | |
228 | msg << "Error opening file for reading: " << filename << endl; | |
229 | log_error(msg.str()); | |
230 | } | |
254bbf53 BS |
231 | } |
232 | ||
233 | ||
234 | /** | |
667c672c BS |
235 | * A file could not be opened for writing. |
236 | * @param filename The filename. | |
237 | */ | |
b38684ce | 238 | void Logger::print_error_opening_rw(const string& filename) const |
667c672c BS |
239 | { |
240 | if ( 0 <= Loglevel ) | |
241 | { | |
242 | ostringstream msg; | |
243 | msg << "Error opening file for writing: " << filename << endl; | |
244 | log_error(msg.str()); | |
245 | } | |
246 | } | |
247 | ||
248 | ||
249 | /** | |
254bbf53 BS |
250 | * Desctructor of specified class was called. |
251 | * @param _class Name of the class. | |
252 | */ | |
b38684ce | 253 | void Logger::print_destructor_call(const string& _class) const |
254bbf53 | 254 | { |
59c8d63c BS |
255 | if ( 1 <= Loglevel ) |
256 | { | |
257 | ostringstream msg; | |
258 | msg << "Destructor call: " << _class << endl; | |
259 | log_notice(msg.str()); | |
260 | } | |
254bbf53 BS |
261 | } |
262 | ||
263 | ||
264 | /** | |
265 | * Constructor of specified class was called. | |
266 | * @param _class Name of the class. | |
267 | */ | |
b38684ce | 268 | void Logger::print_constructor_call(const string& _class) const |
254bbf53 | 269 | { |
59c8d63c BS |
270 | if ( 1 <= Loglevel ) |
271 | { | |
272 | ostringstream msg; | |
273 | msg << "Constructor call: " << _class << endl; | |
274 | log_notice(msg.str()); | |
275 | } | |
254bbf53 BS |
276 | } |
277 | ||
278 | ||
279 | /** | |
280 | * Update method for specified service was called. | |
daf2ea82 | 281 | * @param service The service for which is the update running. |
254bbf53 | 282 | */ |
b38684ce | 283 | void Logger::print_update_service(const string& service) const |
254bbf53 | 284 | { |
59c8d63c BS |
285 | if ( 0 <= Loglevel ) |
286 | { | |
287 | ostringstream msg; | |
288 | msg << "Running update for service: " << service << endl; | |
289 | log_notice(msg.str()); | |
290 | } | |
254bbf53 BS |
291 | } |
292 | ||
293 | ||
daf2ea82 BS |
294 | /** |
295 | * An unknown option on the command line was detected. | |
296 | * @param unknown_option The unknown option. | |
297 | */ | |
b38684ce | 298 | void Logger::print_unknown_cmd_option(const string& unknown_option) const |
254bbf53 | 299 | { |
59c8d63c BS |
300 | if ( 0 <= Loglevel ) |
301 | { | |
302 | ostringstream msg; | |
303 | msg << "Unknown option on command line detected: " << unknown_option << endl; | |
304 | log_error(msg.str()); | |
305 | } | |
254bbf53 BS |
306 | } |
307 | ||
308 | ||
daf2ea82 BS |
309 | /** |
310 | * An unknown protocol was specified. | |
311 | * @param protocol The unknown protocol. | |
312 | */ | |
b38684ce | 313 | void Logger::print_unknown_protocol(const string& protocol) const |
254bbf53 | 314 | { |
59c8d63c BS |
315 | if ( 0 <= Loglevel ) |
316 | { | |
317 | ostringstream msg; | |
318 | msg << "Unknown protocol defined: " << protocol << endl; | |
319 | log_error(msg.str()); | |
320 | } | |
254bbf53 BS |
321 | } |
322 | ||
323 | ||
daf2ea82 BS |
324 | /** |
325 | * Loading a service config file. | |
326 | * @param filename The service config file. | |
327 | */ | |
b38684ce | 328 | void Logger::print_load_service_conf(const string& filename) const |
254bbf53 | 329 | { |
59c8d63c BS |
330 | if ( 1 <= Loglevel ) |
331 | { | |
332 | ostringstream msg; | |
333 | msg << "Loading service config file: " << filename << endl; | |
334 | log_notice(msg.str()); | |
335 | } | |
254bbf53 BS |
336 | } |
337 | ||
338 | ||
daf2ea82 BS |
339 | /** |
340 | * Loading the main config file. | |
341 | * @param filename The main config file. | |
342 | */ | |
b38684ce | 343 | void Logger::print_load_main_conf(const string& filename) const |
254bbf53 | 344 | { |
59c8d63c BS |
345 | if ( 1 <= Loglevel ) |
346 | { | |
347 | ostringstream msg; | |
348 | msg << "Loading main config file: " << filename << endl; | |
349 | log_notice(msg.str()); | |
350 | } | |
254bbf53 BS |
351 | } |
352 | ||
353 | ||
daf2ea82 BS |
354 | /** |
355 | * There is an unknown option in a service config file. | |
356 | * @param unknown_option The unknown option. | |
357 | */ | |
8a00a649 | 358 | void Logger::print_unknown_service_conf_option(const string& service_conf_file, const string& unknown_option) const |
254bbf53 | 359 | { |
59c8d63c BS |
360 | if ( 0 <= Loglevel ) |
361 | { | |
362 | ostringstream msg; | |
8a00a649 | 363 | msg << "Unknown option in service config file detected: " << service_conf_file << " Unknown option: " << unknown_option << endl; |
59c8d63c BS |
364 | log_error(msg.str()); |
365 | } | |
254bbf53 BS |
366 | } |
367 | ||
368 | ||
daf2ea82 BS |
369 | /** |
370 | * There is an unknown option in the main config file. | |
371 | * @param unknown_option The unknown option. | |
372 | */ | |
b38684ce | 373 | void Logger::print_unknown_main_conf_option(const string& unknown_option) const |
254bbf53 | 374 | { |
59c8d63c BS |
375 | if ( 0 <= Loglevel ) |
376 | { | |
377 | ostringstream msg; | |
378 | msg << "Unknown option in main config file detected: " << unknown_option << endl; | |
379 | log_error(msg.str()); | |
380 | } | |
254bbf53 BS |
381 | } |
382 | ||
383 | ||
daf2ea82 BS |
384 | /** |
385 | * The defined config path doesn't exist or is not a directory. | |
386 | * @param config_path The defined config path. | |
387 | */ | |
b38684ce | 388 | void Logger::print_error_config_path(const string& config_path) const |
254bbf53 | 389 | { |
59c8d63c BS |
390 | if ( 0 <= Loglevel ) |
391 | { | |
392 | ostringstream msg; | |
393 | msg << "Config path doesn't exists or is not a diretory: " << config_path << endl; | |
394 | log_error(msg.str()); | |
395 | } | |
254bbf53 BS |
396 | } |
397 | ||
398 | ||
daf2ea82 BS |
399 | /** |
400 | * There is a missing command line option to initialize a service object. | |
401 | */ | |
b38684ce | 402 | void Logger::print_missing_cmd_service_option() const |
254bbf53 | 403 | { |
59c8d63c BS |
404 | if ( 0 <= Loglevel ) |
405 | { | |
406 | ostringstream msg; | |
407 | msg << "Missing option to initialize service. Protocol, host, login and password must be specified." << endl; | |
408 | log_error(msg.str()); | |
409 | } | |
254bbf53 | 410 | } |
388f4ab0 BS |
411 | |
412 | ||
c5675c01 | 413 | /** |
8a00a649 BS |
414 | * Missing option in service config file. |
415 | * @param service_conf_file Service config file | |
416 | */ | |
417 | void Logger::print_missing_service_conf_option(const string& service_conf_file) const | |
418 | { | |
419 | if ( 0 <= Loglevel ) | |
420 | { | |
421 | ostringstream msg; | |
422 | msg << "Missing option in service config file " << service_conf_file << " to initialize service. Protocol, host, login and password must be specified." << endl; | |
423 | log_error(msg.str()); | |
424 | } | |
425 | } | |
426 | ||
427 | ||
428 | /** | |
c5675c01 BS |
429 | * Process running as daemon. |
430 | * @param pid The pid of the daemon. | |
431 | */ | |
b38684ce | 432 | void Logger::print_runnig_as_daemon(const int pid) const |
388f4ab0 | 433 | { |
59c8d63c BS |
434 | if ( 1 <= Loglevel ) |
435 | { | |
436 | ostringstream msg; | |
437 | msg << "Runnig as daemon: " << pid << endl; | |
438 | log_notice(msg.str()); | |
439 | } | |
388f4ab0 BS |
440 | } |
441 | ||
c5675c01 BS |
442 | |
443 | /** | |
444 | * Prints out the daemon mode. | |
445 | * @param daemon_mode The daemon mode. | |
446 | */ | |
b38684ce | 447 | void Logger::print_daemon_mode(const bool daemon_mode) const |
388f4ab0 | 448 | { |
59c8d63c BS |
449 | if ( 1 <= Loglevel ) |
450 | { | |
451 | string mode = "disabled"; | |
452 | if (daemon_mode == true) | |
453 | mode = "enabled"; | |
454 | ostringstream msg; | |
455 | msg << "Daemon mode is " << mode << "." << endl; | |
456 | log_notice(msg.str()); | |
457 | } | |
388f4ab0 BS |
458 | } |
459 | ||
460 | ||
c5675c01 BS |
461 | /** |
462 | * There was an error while trying to fork. | |
463 | */ | |
b38684ce | 464 | void Logger::print_error_fork() const |
388f4ab0 | 465 | { |
59c8d63c BS |
466 | if ( 0 <= Loglevel ) |
467 | { | |
468 | ostringstream msg; | |
469 | msg << "Error while trying to fork." << endl; | |
470 | log_notice(msg.str()); | |
471 | } | |
388f4ab0 BS |
472 | } |
473 | ||
474 | ||
c5675c01 BS |
475 | /** |
476 | * A pid in the pidfile was found. | |
477 | * @param pid The pid found in the pidfile. | |
478 | */ | |
b38684ce | 479 | void Logger::print_pid_found(const int pid) const |
388f4ab0 | 480 | { |
59c8d63c BS |
481 | if ( 1 <= Loglevel ) |
482 | { | |
483 | ostringstream msg; | |
484 | msg << "Pidfile found: " << pid << ". Checking if process is still runnig..." << endl; | |
485 | log_notice(msg.str()); | |
486 | } | |
388f4ab0 BS |
487 | } |
488 | ||
489 | ||
c5675c01 BS |
490 | /** |
491 | * Another process is already running. | |
492 | * @param pid The pid of the other process. | |
493 | */ | |
b38684ce | 494 | void Logger::print_process_already_running(const int pid) const |
388f4ab0 | 495 | { |
59c8d63c BS |
496 | if ( 0 <= Loglevel ) |
497 | { | |
498 | ostringstream msg; | |
499 | msg << "Another bpdyndnsd process with PID " << pid << " is already running!" << endl; | |
500 | log_error(msg.str()); | |
501 | } | |
388f4ab0 | 502 | } |
c5675c01 BS |
503 | |
504 | ||
505 | /** | |
506 | * SIGTERM caught. | |
507 | */ | |
b38684ce | 508 | void Logger::print_caught_sigterm() const |
c5675c01 | 509 | { |
59c8d63c BS |
510 | if ( 0 <= Loglevel ) |
511 | { | |
512 | ostringstream msg; | |
513 | msg << "Caught SIGTERM. Exiting..." << endl; | |
514 | log_notice(msg.str()); | |
515 | } | |
c5675c01 BS |
516 | } |
517 | ||
518 | ||
519 | /** | |
520 | * SIGUSR1 caught. | |
521 | */ | |
b38684ce | 522 | void Logger::print_caught_siguser1() const |
c5675c01 | 523 | { |
59c8d63c BS |
524 | if ( 0 <= Loglevel ) |
525 | { | |
526 | ostringstream msg; | |
527 | msg << "Caught SIGUSR1. Switching to offline mode..." << endl; | |
528 | log_notice(msg.str()); | |
529 | } | |
c5675c01 BS |
530 | } |
531 | ||
532 | ||
533 | /** | |
534 | * SIGHUP caught. | |
535 | */ | |
b38684ce | 536 | void Logger::print_caught_sighup() const |
c5675c01 | 537 | { |
59c8d63c BS |
538 | if ( 0 <= Loglevel ) |
539 | { | |
540 | ostringstream msg; | |
541 | msg << "Caught SIGHUP. Reloading config and switching to online mode..." << endl; | |
542 | log_notice(msg.str()); | |
543 | } | |
c5675c01 | 544 | } |
8bca3c5d BS |
545 | |
546 | ||
547 | /** | |
548 | * Error while setting signal handler. | |
549 | */ | |
b38684ce | 550 | void Logger::print_error_setting_signal(const string& signal) const |
8bca3c5d | 551 | { |
59c8d63c BS |
552 | if ( 0 <= Loglevel ) |
553 | { | |
554 | ostringstream msg; | |
667c672c | 555 | msg << "Error while setting signal handler for: " << signal << endl; |
59c8d63c BS |
556 | log_error(msg.str()); |
557 | } | |
8bca3c5d BS |
558 | } |
559 | ||
560 | ||
561 | /** | |
562 | * Error while setting signal handler. | |
563 | */ | |
b38684ce | 564 | void Logger::print_init_log_facility() const |
8bca3c5d | 565 | { |
59c8d63c BS |
566 | if ( 1 <= Loglevel ) |
567 | { | |
568 | ostringstream msg; | |
569 | msg << "Initialized logging facility." << " Loglevel: " << Loglevel << " Syslog: " << Syslog << endl; | |
570 | log_notice(msg.str()); | |
571 | } | |
8bca3c5d BS |
572 | } |
573 | ||
27baf279 | 574 | |
8bca3c5d BS |
575 | /** |
576 | * Be verbose. Currently we are in offline mode. | |
577 | */ | |
b38684ce | 578 | void Logger::print_offline_mode() const |
8bca3c5d | 579 | { |
59c8d63c BS |
580 | if ( 0 <= Loglevel ) |
581 | { | |
582 | ostringstream msg; | |
583 | msg << "Offline mode..." << endl; | |
584 | log_notice(msg.str()); | |
585 | } | |
8bca3c5d | 586 | } |
27baf279 BS |
587 | |
588 | ||
589 | /** | |
590 | * Objects successfully serialized. | |
591 | */ | |
b38684ce | 592 | void Logger::print_serialized_objects_success() const |
27baf279 BS |
593 | { |
594 | if ( 1 <= Loglevel ) | |
595 | { | |
596 | ostringstream msg; | |
597 | msg << "Serialized objects successfully." << endl; | |
598 | log_notice(msg.str()); | |
599 | } | |
600 | } | |
601 | ||
602 | ||
603 | /** | |
604 | * Objects successfully de-serialized. | |
605 | */ | |
b38684ce | 606 | void Logger::print_deserialized_objects_success() const |
27baf279 BS |
607 | { |
608 | if ( 1 <= Loglevel ) | |
609 | { | |
610 | ostringstream msg; | |
611 | msg << "De-serialized objects successfully." << endl; | |
612 | log_notice(msg.str()); | |
613 | } | |
614 | } | |
615 | ||
616 | ||
5d38cfe6 BS |
617 | /** |
618 | * Prints out the content of a service object. | |
619 | * @param message Message to be added on output first. | |
620 | * @param protocol Service's protocol. | |
621 | * @param hostname Service's hostname. | |
622 | * @param login Service's login. | |
623 | * @param password Service's password. | |
624 | * @param actual_ip Service's actual_ip. | |
625 | * @param lastupdated Service's lastupdated. | |
626 | */ | |
3c0cd271 | 627 | 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 string& actual_ip, list<int>* lastupdated) const |
27baf279 BS |
628 | { |
629 | if ( 1 <= Loglevel ) | |
630 | { | |
631 | ostringstream msg; | |
632 | msg << message << endl; | |
3c0cd271 BS |
633 | msg << "\t" << "Protocol: " << protocol << endl; |
634 | msg << "\t" << "Hostname: " << hostname << endl; | |
635 | msg << "\t" << "Login: " << login << endl; | |
636 | msg << "\t" << "Password: " << password << endl; | |
637 | msg << "\t" << "Update Interval: " << update_interval << endl; | |
638 | msg << "\t" << "Max Updates: " << max_updates_within_interval << endl; | |
639 | msg << "\t" << "Actual_IP: " << actual_ip << endl; | |
640 | BOOST_FOREACH( int update_time, *lastupdated) | |
641 | { | |
642 | msg << "\t" << "Lastupdated: " << update_time << endl; | |
643 | } | |
27baf279 BS |
644 | log_notice(msg.str()); |
645 | } | |
646 | } | |
5d38cfe6 BS |
647 | |
648 | ||
649 | /** | |
650 | * Caught exception while serialize. | |
651 | * @param exception Exception message. | |
652 | */ | |
b38684ce | 653 | void Logger::print_exception_serialize(const string& exception) const |
5d38cfe6 | 654 | { |
667c672c BS |
655 | if ( 0 <= Loglevel ) |
656 | { | |
657 | ostringstream msg; | |
658 | msg << "Error while trying to serialize Serviceholder object: " << exception << endl; | |
659 | log_error(msg.str()); | |
660 | } | |
661 | } | |
662 | ||
663 | ||
664 | /** | |
665 | * Caught exception while de-serialize. | |
666 | * @param exception Exception message. | |
667 | */ | |
e8d4a6f8 | 668 | void Logger::print_exception_deserialize(const string& exception) const |
667c672c BS |
669 | { |
670 | if ( 0 <= Loglevel ) | |
671 | { | |
672 | ostringstream msg; | |
673 | msg << "Error while trying to de-serialize Serviceholder object: " << exception << endl; | |
674 | log_error(msg.str()); | |
675 | } | |
676 | } | |
677 | ||
678 | ||
679 | /** | |
680 | * Child couldn't be killed by parent. | |
681 | * @param pid Pid of the child. | |
682 | */ | |
b38684ce | 683 | void Logger::print_error_kill_child(const int pid) const |
667c672c BS |
684 | { |
685 | if ( 0 <= Loglevel ) | |
686 | { | |
687 | ostringstream msg; | |
688 | msg << "Could not kill child process with PID: " << pid << endl; | |
689 | log_error(msg.str()); | |
690 | } | |
691 | } | |
692 | ||
693 | ||
0665b239 BS |
694 | /** |
695 | * Child was killed by parent because of error. | |
696 | * @param pid The pid (child) killed. | |
697 | */ | |
b38684ce | 698 | void Logger::print_child_killed(const int pid) const |
584b9407 BS |
699 | { |
700 | if ( 0 <= Loglevel ) | |
701 | { | |
702 | ostringstream msg; | |
703 | msg << "Killed child process with PID: " << pid << endl; | |
704 | log_notice(msg.str()); | |
705 | } | |
706 | } | |
707 | ||
708 | ||
667c672c BS |
709 | /** |
710 | * There is no object file. | |
711 | * @param object_file The object file. | |
712 | */ | |
e8d4a6f8 | 713 | void Logger::print_no_object_file(const string& object_file) const |
667c672c BS |
714 | { |
715 | if ( 1 <= Loglevel ) | |
716 | { | |
717 | ostringstream msg; | |
718 | msg << "There is no object file: " << object_file << ". Continue without recovering state from old services!" << endl; | |
719 | log_warning(msg.str()); | |
720 | } | |
5d38cfe6 | 721 | } |
0665b239 BS |
722 | |
723 | ||
724 | /** | |
725 | * Prints out the given hostname | |
726 | * @param hostname Hostname as string. | |
727 | */ | |
e8d4a6f8 | 728 | void Logger::print_hostname(const string& hostname) const |
0665b239 BS |
729 | { |
730 | if ( 1 <= Loglevel ) | |
731 | { | |
732 | ostringstream msg; | |
733 | msg << "Detected following hostname of localhost: " << hostname << endl; | |
734 | log_notice(msg.str()); | |
735 | } | |
736 | } | |
737 | ||
738 | ||
739 | /** | |
019dc0d9 | 740 | * Prints out the detected own ipv4 address |
0665b239 BS |
741 | * @param ip_addr String representation of the detected ip. |
742 | */ | |
c3dea5dc | 743 | void Logger::print_own_ipv4(const string& ip_addr_v4, const string& hostname) const |
0665b239 BS |
744 | { |
745 | if ( 1 <= Loglevel ) | |
746 | { | |
747 | ostringstream msg; | |
c3dea5dc | 748 | msg << "Detected following IPv4-Address of host: " << hostname << " : " << ip_addr_v4 << endl; |
019dc0d9 BS |
749 | log_notice(msg.str()); |
750 | } | |
751 | } | |
752 | ||
753 | ||
754 | /** | |
755 | * Prints out the detected own ipv5 address | |
756 | * @param ip_addr String representation of the detected ip. | |
757 | */ | |
c3dea5dc | 758 | void Logger::print_own_ipv6(const string& ip_addr_v6, const string& hostname) const |
019dc0d9 BS |
759 | { |
760 | if ( 1 <= Loglevel ) | |
761 | { | |
762 | ostringstream msg; | |
c3dea5dc | 763 | msg << "Detected following IPv6-Address of host: " << hostname << " : " << ip_addr_v6 << endl; |
0665b239 BS |
764 | log_notice(msg.str()); |
765 | } | |
766 | } | |
767 | ||
768 | ||
769 | /** | |
770 | * Exception while trying to resolve hostname to ip. | |
771 | * @param exception The exception caught. | |
772 | * @param hostname The hostname. | |
773 | */ | |
1c0908b5 | 774 | void Logger::print_error_hostname_to_ip(const string& exception, const string& hostname) const |
0665b239 BS |
775 | { |
776 | if ( 1 <= Loglevel ) | |
777 | { | |
778 | ostringstream msg; | |
c3dea5dc | 779 | msg << "Could not resolve the hostname: " << hostname << " to an IP-Address: " << exception << endl; |
0665b239 BS |
780 | log_error(msg.str()); |
781 | } | |
782 | } | |
68c6b4af BS |
783 | |
784 | ||
1c0908b5 BS |
785 | /** |
786 | * The update of the given service was successful. | |
787 | * @param service The service. | |
788 | */ | |
789 | void Logger::print_update_service_successful(const string& service) const | |
68c6b4af BS |
790 | { |
791 | if ( 0 <= Loglevel ) | |
792 | { | |
793 | ostringstream msg; | |
794 | msg << "Updated service successful: " << service << endl; | |
1c0908b5 BS |
795 | log_notice(msg.str()); |
796 | } | |
797 | } | |
798 | ||
799 | ||
800 | /** | |
801 | * No ip could be determined through webcheck | |
802 | */ | |
803 | void Logger::print_webcheck_no_ip() const | |
804 | { | |
805 | if ( 0 <= Loglevel ) | |
806 | { | |
807 | ostringstream msg; | |
808 | msg << "This hosts' IP could not be determined through any configured webcheck url." << endl; | |
809 | log_error(msg.str()); | |
810 | } | |
811 | } | |
812 | ||
813 | ||
814 | /** | |
815 | * Connection problem while trying to get ip through webcheck url | |
816 | * @param curl_err_buff Curl error message | |
817 | * @param url the url | |
818 | */ | |
819 | void Logger::print_webcheck_url_connection_problem(const char * curl_err_buff, const string& url) const | |
820 | { | |
821 | if ( 1 <= Loglevel ) | |
822 | { | |
823 | ostringstream msg; | |
824 | msg << "There was a problem while trying to connect to following URL: " << url << " CURL error: " << curl_err_buff << endl; | |
825 | log_warning(msg.str()); | |
826 | } | |
827 | } | |
828 | ||
829 | ||
830 | /** | |
831 | * Prints out curl error. | |
832 | * @param curl_err_buff Curl error message. | |
833 | * @param url URL | |
834 | */ | |
835 | void Logger::print_webcheck_error(const char * curl_err_buff, const string& url) const | |
836 | { | |
837 | if ( 0 <= Loglevel ) | |
838 | { | |
839 | ostringstream msg; | |
840 | msg << "There was an error while trying to connect to following URL: " << url << " CURL error: " << curl_err_buff << endl; | |
68c6b4af BS |
841 | log_error(msg.str()); |
842 | } | |
843 | } | |
1c0908b5 BS |
844 | |
845 | ||
846 | /** | |
847 | * Prints out the received data through curl. | |
848 | * @param curl_data Data string | |
849 | */ | |
850 | void Logger::print_received_curl_data(const string& curl_data) const | |
851 | { | |
852 | if ( 1 <= Loglevel ) | |
853 | { | |
854 | ostringstream msg; | |
855 | msg << "Received CURL data: " << curl_data << endl; | |
856 | log_notice(msg.str()); | |
857 | } | |
858 | } | |
859 | ||
860 | ||
861 | /** | |
862 | * IP was foudn through regex | |
863 | * @param ip The IP found. | |
864 | */ | |
865 | void Logger::print_regex_found_ip(const string& ip) const | |
866 | { | |
867 | if ( 1 <= Loglevel ) | |
868 | { | |
869 | ostringstream msg; | |
870 | msg << "Found IP-Address via regex: " << ip << endl; | |
871 | log_notice(msg.str()); | |
872 | } | |
873 | } | |
874 | ||
875 | ||
876 | /** | |
877 | * No IP was found through regex. | |
878 | * @param data The data string which should contain a valid IP.s | |
879 | */ | |
880 | void Logger::print_regex_ip_not_found(const string& data) const | |
881 | { | |
882 | if ( 0 <= Loglevel ) | |
883 | { | |
884 | ostringstream msg; | |
885 | msg << "Could not extract an IP-Address via regex from following data:\n" << data << endl; | |
886 | log_warning(msg.str()); | |
887 | } | |
888 | } | |
3c0cd271 BS |
889 | |
890 | ||
891 | /** | |
892 | * Detected multiple occurrences of the same option. | |
893 | * @param message Error message. | |
894 | */ | |
895 | void Logger::print_multiple_cmd_option(const string& message) const | |
896 | { | |
897 | if ( 0 <= Loglevel ) | |
898 | { | |
899 | ostringstream msg; | |
900 | msg << "The same option is only allowed once: " << message << endl; | |
901 | log_error(msg.str()); | |
902 | } | |
903 | } | |
904 | ||
905 | ||
906 | /** | |
907 | * An update would exceed the update interval. Prints out a warning message. | |
908 | * @param current_time Current time. | |
909 | * @param old_time Time of update #MaxUpdatesWithinInterval ago. | |
910 | * @param MaxUpdatesWithinInterval Number of allowed updates in one update interval. | |
911 | * @param service The service which exceeds update interval. | |
912 | */ | |
913 | void Logger::print_update_not_allowed(const int current_time, const int old_time, const int MaxUpdatesWithinInterval, const string& service) const | |
914 | { | |
915 | if ( 0 <= Loglevel ) | |
916 | { | |
917 | ostringstream msg; | |
918 | 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; | |
919 | log_warning(msg.str()); | |
920 | } | |
921 | } | |
922 | ||
923 | ||
924 | /** | |
925 | * Failure while running update for service. | |
926 | * @param service Services' name. | |
927 | */ | |
e8d4a6f8 | 928 | void Logger::print_update_service_failure(const string& service) const |
3c0cd271 BS |
929 | { |
930 | if ( 0 <= Loglevel ) | |
931 | { | |
932 | ostringstream msg; | |
933 | msg << "Could not update service: " << service << endl; | |
934 | log_warning(msg.str()); | |
935 | } | |
936 | } | |
e304c27b BS |
937 | |
938 | ||
939 | /** | |
940 | * Starting shutdown | |
941 | */ | |
942 | void Logger::print_starting_shutdown() const | |
943 | { | |
944 | if ( 0 <= Loglevel ) | |
945 | { | |
946 | ostringstream msg; | |
947 | msg << "Shutting down ..." << endl; | |
948 | log_notice(msg.str()); | |
949 | } | |
950 | } | |
951 | ||
952 | ||
953 | /** | |
954 | * Shutdown complete | |
955 | */ | |
956 | void Logger::print_shutdown_succeeded() const | |
957 | { | |
958 | if ( 0 <= Loglevel ) | |
959 | { | |
960 | ostringstream msg; | |
961 | msg << "Shutting down complete ..." << endl; | |
962 | log_notice(msg.str()); | |
963 | } | |
964 | } | |
965 | ||
966 | ||
967 | /** | |
968 | * Shutdown parent succeeded | |
969 | */ | |
970 | void Logger::print_shutdown_parent_succeeded() const | |
971 | { | |
972 | if ( 0 <= Loglevel ) | |
973 | { | |
974 | ostringstream msg; | |
975 | msg << "Shutting down parent process completed ..." << endl; | |
976 | log_notice(msg.str()); | |
977 | } | |
978 | } | |
979 | ||
980 | ||
981 | /** | |
982 | * Starting shutdown parent | |
983 | */ | |
984 | void Logger::print_starting_shutdown_parent() const | |
985 | { | |
986 | if ( 0 <= Loglevel ) | |
987 | { | |
988 | ostringstream msg; | |
989 | msg << "Shutting down parent process ..." << endl; | |
990 | log_notice(msg.str()); | |
991 | } | |
992 | } | |
0541cd71 BS |
993 | |
994 | ||
995 | /** | |
996 | * DNS cache record timeout | |
997 | * @param hostname Hostname | |
998 | * @param lastupdated Lastupdated | |
999 | * @param dns_cache_ttl DNS cache TTL | |
1000 | * @param current_time Current time | |
1001 | */ | |
8a00a649 | 1002 | void Logger::print_recheck_dns_entry(const string& hostname, const int lastupdated, const int dns_cache_ttl, const int current_time) const |
0541cd71 BS |
1003 | { |
1004 | if ( 1 <= Loglevel ) | |
1005 | { | |
1006 | ostringstream msg; | |
1007 | msg << "DNS cache record for host <" << hostname << "> expired: Lastupdated: " << lastupdated << " DNS cache ttl: " << dns_cache_ttl << " Current time: " << current_time << " Checking current DNS cache status." << endl; | |
1008 | log_notice(msg.str()); | |
1009 | } | |
1010 | } | |
1011 | ||
1012 | ||
1013 | /** | |
1014 | * Found following cached DNS record | |
1015 | * @param hostname Hostname | |
1016 | * @param cached_dns_entry IP | |
1017 | */ | |
8a00a649 | 1018 | void Logger::print_cached_dns_entry(const string& hostname, const string& cached_dns_entry, const string& lastupdated_ip) const |
0541cd71 BS |
1019 | { |
1020 | if ( 1 <= Loglevel ) | |
1021 | { | |
1022 | ostringstream msg; | |
1023 | msg << "Cached DNS record for host <" << hostname << "> : " << cached_dns_entry << " Last updated IP: " << lastupdated_ip << endl; | |
1024 | log_notice(msg.str()); | |
1025 | } | |
1026 | } | |
8a00a649 BS |
1027 | |
1028 | ||
1029 | /** | |
1030 | * Missing proxy option on command line. | |
1031 | */ | |
1032 | void Logger::print_missing_cmd_proxy_option() const | |
1033 | { | |
1034 | if ( 0 <= Loglevel ) | |
1035 | { | |
1036 | ostringstream msg; | |
1037 | msg << "Missing option to initialize proxy. http_proxy and http_proxy_port must be specified." << endl; | |
1038 | log_error(msg.str()); | |
1039 | } | |
1040 | } | |
1041 | ||
1042 | ||
1043 | /** | |
1044 | * Multiple option in service config file. | |
1045 | * @param service_conf_file Service config file | |
1046 | * @param message Multiple option text | |
1047 | */ | |
1048 | void Logger::print_multiple_service_conf_option(const string& service_conf_file, const string& message) const | |
1049 | { | |
1050 | if ( 0 <= Loglevel ) | |
1051 | { | |
1052 | ostringstream msg; | |
1053 | msg << "Multiple occurrences of the same option in service config file detected: " << service_conf_file << " " << message << endl; | |
1054 | log_error(msg.str()); | |
1055 | } | |
1056 | } | |
1057 | ||
1058 | ||
1059 | /** | |
1060 | * Multiple option in main config file. | |
1061 | * @param service_conf_file Service config file | |
1062 | * @param message Multiple option text | |
1063 | */ | |
1064 | void Logger::print_multiple_main_conf_option(const string& main_conf_file, const string& message) const | |
1065 | { | |
1066 | if ( 0 <= Loglevel ) | |
1067 | { | |
1068 | ostringstream msg; | |
1069 | msg << "Multiple occurrences of the same option in main config file detected: " << main_conf_file << " " << message << endl; | |
1070 | log_error(msg.str()); | |
1071 | } | |
1072 | } | |
1073 | ||
1074 | ||
1075 | /** | |
1076 | * Missing proxy option in main config file. | |
1077 | */ | |
1078 | void Logger::print_missing_conf_proxy_option(const string& main_conf_filename) const | |
1079 | { | |
1080 | if ( 0 <= Loglevel ) | |
1081 | { | |
1082 | ostringstream msg; | |
1083 | msg << "Missing option to initialize proxy in main config file: " << main_conf_filename << " http_proxy and http_proxy_port must be specified." << endl; | |
1084 | log_error(msg.str()); | |
1085 | } | |
1086 | } |