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 | */ | |
b38684ce | 358 | void Logger::print_unknown_service_conf_option(const string& unknown_option) const |
254bbf53 | 359 | { |
59c8d63c BS |
360 | if ( 0 <= Loglevel ) |
361 | { | |
362 | ostringstream msg; | |
363 | msg << "Unknown option in service config file detected: " << unknown_option << endl; | |
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 BS |
413 | /** |
414 | * Process running as daemon. | |
415 | * @param pid The pid of the daemon. | |
416 | */ | |
b38684ce | 417 | void Logger::print_runnig_as_daemon(const int pid) const |
388f4ab0 | 418 | { |
59c8d63c BS |
419 | if ( 1 <= Loglevel ) |
420 | { | |
421 | ostringstream msg; | |
422 | msg << "Runnig as daemon: " << pid << endl; | |
423 | log_notice(msg.str()); | |
424 | } | |
388f4ab0 BS |
425 | } |
426 | ||
c5675c01 BS |
427 | |
428 | /** | |
429 | * Prints out the daemon mode. | |
430 | * @param daemon_mode The daemon mode. | |
431 | */ | |
b38684ce | 432 | void Logger::print_daemon_mode(const bool daemon_mode) const |
388f4ab0 | 433 | { |
59c8d63c BS |
434 | if ( 1 <= Loglevel ) |
435 | { | |
436 | string mode = "disabled"; | |
437 | if (daemon_mode == true) | |
438 | mode = "enabled"; | |
439 | ostringstream msg; | |
440 | msg << "Daemon mode is " << mode << "." << endl; | |
441 | log_notice(msg.str()); | |
442 | } | |
388f4ab0 BS |
443 | } |
444 | ||
445 | ||
c5675c01 BS |
446 | /** |
447 | * There was an error while trying to fork. | |
448 | */ | |
b38684ce | 449 | void Logger::print_error_fork() const |
388f4ab0 | 450 | { |
59c8d63c BS |
451 | if ( 0 <= Loglevel ) |
452 | { | |
453 | ostringstream msg; | |
454 | msg << "Error while trying to fork." << endl; | |
455 | log_notice(msg.str()); | |
456 | } | |
388f4ab0 BS |
457 | } |
458 | ||
459 | ||
c5675c01 BS |
460 | /** |
461 | * A pid in the pidfile was found. | |
462 | * @param pid The pid found in the pidfile. | |
463 | */ | |
b38684ce | 464 | void Logger::print_pid_found(const int pid) const |
388f4ab0 | 465 | { |
59c8d63c BS |
466 | if ( 1 <= Loglevel ) |
467 | { | |
468 | ostringstream msg; | |
469 | msg << "Pidfile found: " << pid << ". Checking if process is still runnig..." << endl; | |
470 | log_notice(msg.str()); | |
471 | } | |
388f4ab0 BS |
472 | } |
473 | ||
474 | ||
c5675c01 BS |
475 | /** |
476 | * Another process is already running. | |
477 | * @param pid The pid of the other process. | |
478 | */ | |
b38684ce | 479 | void Logger::print_process_already_running(const int pid) const |
388f4ab0 | 480 | { |
59c8d63c BS |
481 | if ( 0 <= Loglevel ) |
482 | { | |
483 | ostringstream msg; | |
484 | msg << "Another bpdyndnsd process with PID " << pid << " is already running!" << endl; | |
485 | log_error(msg.str()); | |
486 | } | |
388f4ab0 | 487 | } |
c5675c01 BS |
488 | |
489 | ||
490 | /** | |
491 | * SIGTERM caught. | |
492 | */ | |
b38684ce | 493 | void Logger::print_caught_sigterm() const |
c5675c01 | 494 | { |
59c8d63c BS |
495 | if ( 0 <= Loglevel ) |
496 | { | |
497 | ostringstream msg; | |
498 | msg << "Caught SIGTERM. Exiting..." << endl; | |
499 | log_notice(msg.str()); | |
500 | } | |
c5675c01 BS |
501 | } |
502 | ||
503 | ||
504 | /** | |
505 | * SIGUSR1 caught. | |
506 | */ | |
b38684ce | 507 | void Logger::print_caught_siguser1() const |
c5675c01 | 508 | { |
59c8d63c BS |
509 | if ( 0 <= Loglevel ) |
510 | { | |
511 | ostringstream msg; | |
512 | msg << "Caught SIGUSR1. Switching to offline mode..." << endl; | |
513 | log_notice(msg.str()); | |
514 | } | |
c5675c01 BS |
515 | } |
516 | ||
517 | ||
518 | /** | |
519 | * SIGHUP caught. | |
520 | */ | |
b38684ce | 521 | void Logger::print_caught_sighup() const |
c5675c01 | 522 | { |
59c8d63c BS |
523 | if ( 0 <= Loglevel ) |
524 | { | |
525 | ostringstream msg; | |
526 | msg << "Caught SIGHUP. Reloading config and switching to online mode..." << endl; | |
527 | log_notice(msg.str()); | |
528 | } | |
c5675c01 | 529 | } |
8bca3c5d BS |
530 | |
531 | ||
532 | /** | |
533 | * Error while setting signal handler. | |
534 | */ | |
b38684ce | 535 | void Logger::print_error_setting_signal(const string& signal) const |
8bca3c5d | 536 | { |
59c8d63c BS |
537 | if ( 0 <= Loglevel ) |
538 | { | |
539 | ostringstream msg; | |
667c672c | 540 | msg << "Error while setting signal handler for: " << signal << endl; |
59c8d63c BS |
541 | log_error(msg.str()); |
542 | } | |
8bca3c5d BS |
543 | } |
544 | ||
545 | ||
546 | /** | |
547 | * Error while setting signal handler. | |
548 | */ | |
b38684ce | 549 | void Logger::print_init_log_facility() const |
8bca3c5d | 550 | { |
59c8d63c BS |
551 | if ( 1 <= Loglevel ) |
552 | { | |
553 | ostringstream msg; | |
554 | msg << "Initialized logging facility." << " Loglevel: " << Loglevel << " Syslog: " << Syslog << endl; | |
555 | log_notice(msg.str()); | |
556 | } | |
8bca3c5d BS |
557 | } |
558 | ||
27baf279 | 559 | |
8bca3c5d BS |
560 | /** |
561 | * Be verbose. Currently we are in offline mode. | |
562 | */ | |
b38684ce | 563 | void Logger::print_offline_mode() const |
8bca3c5d | 564 | { |
59c8d63c BS |
565 | if ( 0 <= Loglevel ) |
566 | { | |
567 | ostringstream msg; | |
568 | msg << "Offline mode..." << endl; | |
569 | log_notice(msg.str()); | |
570 | } | |
8bca3c5d | 571 | } |
27baf279 BS |
572 | |
573 | ||
574 | /** | |
575 | * Objects successfully serialized. | |
576 | */ | |
b38684ce | 577 | void Logger::print_serialized_objects_success() const |
27baf279 BS |
578 | { |
579 | if ( 1 <= Loglevel ) | |
580 | { | |
581 | ostringstream msg; | |
582 | msg << "Serialized objects successfully." << endl; | |
583 | log_notice(msg.str()); | |
584 | } | |
585 | } | |
586 | ||
587 | ||
588 | /** | |
589 | * Objects successfully de-serialized. | |
590 | */ | |
b38684ce | 591 | void Logger::print_deserialized_objects_success() const |
27baf279 BS |
592 | { |
593 | if ( 1 <= Loglevel ) | |
594 | { | |
595 | ostringstream msg; | |
596 | msg << "De-serialized objects successfully." << endl; | |
597 | log_notice(msg.str()); | |
598 | } | |
599 | } | |
600 | ||
601 | ||
5d38cfe6 BS |
602 | /** |
603 | * Prints out the content of a service object. | |
604 | * @param message Message to be added on output first. | |
605 | * @param protocol Service's protocol. | |
606 | * @param hostname Service's hostname. | |
607 | * @param login Service's login. | |
608 | * @param password Service's password. | |
609 | * @param actual_ip Service's actual_ip. | |
610 | * @param lastupdated Service's lastupdated. | |
611 | */ | |
3c0cd271 | 612 | 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 |
613 | { |
614 | if ( 1 <= Loglevel ) | |
615 | { | |
616 | ostringstream msg; | |
617 | msg << message << endl; | |
3c0cd271 BS |
618 | msg << "\t" << "Protocol: " << protocol << endl; |
619 | msg << "\t" << "Hostname: " << hostname << endl; | |
620 | msg << "\t" << "Login: " << login << endl; | |
621 | msg << "\t" << "Password: " << password << endl; | |
622 | msg << "\t" << "Update Interval: " << update_interval << endl; | |
623 | msg << "\t" << "Max Updates: " << max_updates_within_interval << endl; | |
624 | msg << "\t" << "Actual_IP: " << actual_ip << endl; | |
625 | BOOST_FOREACH( int update_time, *lastupdated) | |
626 | { | |
627 | msg << "\t" << "Lastupdated: " << update_time << endl; | |
628 | } | |
27baf279 BS |
629 | log_notice(msg.str()); |
630 | } | |
631 | } | |
5d38cfe6 BS |
632 | |
633 | ||
634 | /** | |
635 | * Caught exception while serialize. | |
636 | * @param exception Exception message. | |
637 | */ | |
b38684ce | 638 | void Logger::print_exception_serialize(const string& exception) const |
5d38cfe6 | 639 | { |
667c672c BS |
640 | if ( 0 <= Loglevel ) |
641 | { | |
642 | ostringstream msg; | |
643 | msg << "Error while trying to serialize Serviceholder object: " << exception << endl; | |
644 | log_error(msg.str()); | |
645 | } | |
646 | } | |
647 | ||
648 | ||
649 | /** | |
650 | * Caught exception while de-serialize. | |
651 | * @param exception Exception message. | |
652 | */ | |
b38684ce | 653 | void Logger::print_exception_deserialize(const std::string& exception) const |
667c672c BS |
654 | { |
655 | if ( 0 <= Loglevel ) | |
656 | { | |
657 | ostringstream msg; | |
658 | msg << "Error while trying to de-serialize Serviceholder object: " << exception << endl; | |
659 | log_error(msg.str()); | |
660 | } | |
661 | } | |
662 | ||
663 | ||
664 | /** | |
665 | * Child couldn't be killed by parent. | |
666 | * @param pid Pid of the child. | |
667 | */ | |
b38684ce | 668 | void Logger::print_error_kill_child(const int pid) const |
667c672c BS |
669 | { |
670 | if ( 0 <= Loglevel ) | |
671 | { | |
672 | ostringstream msg; | |
673 | msg << "Could not kill child process with PID: " << pid << endl; | |
674 | log_error(msg.str()); | |
675 | } | |
676 | } | |
677 | ||
678 | ||
0665b239 BS |
679 | /** |
680 | * Child was killed by parent because of error. | |
681 | * @param pid The pid (child) killed. | |
682 | */ | |
b38684ce | 683 | void Logger::print_child_killed(const int pid) const |
584b9407 BS |
684 | { |
685 | if ( 0 <= Loglevel ) | |
686 | { | |
687 | ostringstream msg; | |
688 | msg << "Killed child process with PID: " << pid << endl; | |
689 | log_notice(msg.str()); | |
690 | } | |
691 | } | |
692 | ||
693 | ||
667c672c BS |
694 | /** |
695 | * There is no object file. | |
696 | * @param object_file The object file. | |
697 | */ | |
b38684ce | 698 | void Logger::print_no_object_file(const std::string& object_file) const |
667c672c BS |
699 | { |
700 | if ( 1 <= Loglevel ) | |
701 | { | |
702 | ostringstream msg; | |
703 | msg << "There is no object file: " << object_file << ". Continue without recovering state from old services!" << endl; | |
704 | log_warning(msg.str()); | |
705 | } | |
5d38cfe6 | 706 | } |
0665b239 BS |
707 | |
708 | ||
709 | /** | |
710 | * Prints out the given hostname | |
711 | * @param hostname Hostname as string. | |
712 | */ | |
713 | void Logger::print_hostname(const std::string& hostname) const | |
714 | { | |
715 | if ( 1 <= Loglevel ) | |
716 | { | |
717 | ostringstream msg; | |
718 | msg << "Detected following hostname of localhost: " << hostname << endl; | |
719 | log_notice(msg.str()); | |
720 | } | |
721 | } | |
722 | ||
723 | ||
724 | /** | |
019dc0d9 | 725 | * Prints out the detected own ipv4 address |
0665b239 BS |
726 | * @param ip_addr String representation of the detected ip. |
727 | */ | |
019dc0d9 | 728 | void Logger::print_own_ipv4(const std::string& ip_addr_v4) const |
0665b239 BS |
729 | { |
730 | if ( 1 <= Loglevel ) | |
731 | { | |
732 | ostringstream msg; | |
733 | msg << "Detected following IPv4-Address of this host: " << ip_addr_v4 << endl; | |
019dc0d9 BS |
734 | log_notice(msg.str()); |
735 | } | |
736 | } | |
737 | ||
738 | ||
739 | /** | |
740 | * Prints out the detected own ipv5 address | |
741 | * @param ip_addr String representation of the detected ip. | |
742 | */ | |
743 | void Logger::print_own_ipv6(const std::string& ip_addr_v6) const | |
744 | { | |
745 | if ( 1 <= Loglevel ) | |
746 | { | |
747 | ostringstream msg; | |
0665b239 BS |
748 | msg << "Detected following IPv6-Address of this host: " << ip_addr_v6 << endl; |
749 | log_notice(msg.str()); | |
750 | } | |
751 | } | |
752 | ||
753 | ||
754 | /** | |
755 | * Exception while trying to resolve hostname to ip. | |
756 | * @param exception The exception caught. | |
757 | * @param hostname The hostname. | |
758 | */ | |
1c0908b5 | 759 | void Logger::print_error_hostname_to_ip(const string& exception, const string& hostname) const |
0665b239 BS |
760 | { |
761 | if ( 1 <= Loglevel ) | |
762 | { | |
763 | ostringstream msg; | |
764 | msg << "Could not resolve the hostname: " << hostname << "to an IP-Address: " << exception << endl; | |
765 | log_error(msg.str()); | |
766 | } | |
767 | } | |
68c6b4af BS |
768 | |
769 | ||
1c0908b5 BS |
770 | /** |
771 | * The update of the given service was successful. | |
772 | * @param service The service. | |
773 | */ | |
774 | void Logger::print_update_service_successful(const string& service) const | |
68c6b4af BS |
775 | { |
776 | if ( 0 <= Loglevel ) | |
777 | { | |
778 | ostringstream msg; | |
779 | msg << "Updated service successful: " << service << endl; | |
1c0908b5 BS |
780 | log_notice(msg.str()); |
781 | } | |
782 | } | |
783 | ||
784 | ||
785 | /** | |
786 | * No ip could be determined through webcheck | |
787 | */ | |
788 | void Logger::print_webcheck_no_ip() const | |
789 | { | |
790 | if ( 0 <= Loglevel ) | |
791 | { | |
792 | ostringstream msg; | |
793 | msg << "This hosts' IP could not be determined through any configured webcheck url." << endl; | |
794 | log_error(msg.str()); | |
795 | } | |
796 | } | |
797 | ||
798 | ||
799 | /** | |
800 | * Connection problem while trying to get ip through webcheck url | |
801 | * @param curl_err_buff Curl error message | |
802 | * @param url the url | |
803 | */ | |
804 | void Logger::print_webcheck_url_connection_problem(const char * curl_err_buff, const string& url) const | |
805 | { | |
806 | if ( 1 <= Loglevel ) | |
807 | { | |
808 | ostringstream msg; | |
809 | msg << "There was a problem while trying to connect to following URL: " << url << " CURL error: " << curl_err_buff << endl; | |
810 | log_warning(msg.str()); | |
811 | } | |
812 | } | |
813 | ||
814 | ||
815 | /** | |
816 | * Prints out curl error. | |
817 | * @param curl_err_buff Curl error message. | |
818 | * @param url URL | |
819 | */ | |
820 | void Logger::print_webcheck_error(const char * curl_err_buff, const string& url) const | |
821 | { | |
822 | if ( 0 <= Loglevel ) | |
823 | { | |
824 | ostringstream msg; | |
825 | msg << "There was an error while trying to connect to following URL: " << url << " CURL error: " << curl_err_buff << endl; | |
68c6b4af BS |
826 | log_error(msg.str()); |
827 | } | |
828 | } | |
1c0908b5 BS |
829 | |
830 | ||
831 | /** | |
832 | * Prints out the received data through curl. | |
833 | * @param curl_data Data string | |
834 | */ | |
835 | void Logger::print_received_curl_data(const string& curl_data) const | |
836 | { | |
837 | if ( 1 <= Loglevel ) | |
838 | { | |
839 | ostringstream msg; | |
840 | msg << "Received CURL data: " << curl_data << endl; | |
841 | log_notice(msg.str()); | |
842 | } | |
843 | } | |
844 | ||
845 | ||
846 | /** | |
847 | * IP was foudn through regex | |
848 | * @param ip The IP found. | |
849 | */ | |
850 | void Logger::print_regex_found_ip(const string& ip) const | |
851 | { | |
852 | if ( 1 <= Loglevel ) | |
853 | { | |
854 | ostringstream msg; | |
855 | msg << "Found IP-Address via regex: " << ip << endl; | |
856 | log_notice(msg.str()); | |
857 | } | |
858 | } | |
859 | ||
860 | ||
861 | /** | |
862 | * No IP was found through regex. | |
863 | * @param data The data string which should contain a valid IP.s | |
864 | */ | |
865 | void Logger::print_regex_ip_not_found(const string& data) const | |
866 | { | |
867 | if ( 0 <= Loglevel ) | |
868 | { | |
869 | ostringstream msg; | |
870 | msg << "Could not extract an IP-Address via regex from following data:\n" << data << endl; | |
871 | log_warning(msg.str()); | |
872 | } | |
873 | } | |
3c0cd271 BS |
874 | |
875 | ||
876 | /** | |
877 | * Detected multiple occurrences of the same option. | |
878 | * @param message Error message. | |
879 | */ | |
880 | void Logger::print_multiple_cmd_option(const string& message) const | |
881 | { | |
882 | if ( 0 <= Loglevel ) | |
883 | { | |
884 | ostringstream msg; | |
885 | msg << "The same option is only allowed once: " << message << endl; | |
886 | log_error(msg.str()); | |
887 | } | |
888 | } | |
889 | ||
890 | ||
891 | /** | |
892 | * An update would exceed the update interval. Prints out a warning message. | |
893 | * @param current_time Current time. | |
894 | * @param old_time Time of update #MaxUpdatesWithinInterval ago. | |
895 | * @param MaxUpdatesWithinInterval Number of allowed updates in one update interval. | |
896 | * @param service The service which exceeds update interval. | |
897 | */ | |
898 | void Logger::print_update_not_allowed(const int current_time, const int old_time, const int MaxUpdatesWithinInterval, const string& service) const | |
899 | { | |
900 | if ( 0 <= Loglevel ) | |
901 | { | |
902 | ostringstream msg; | |
903 | 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; | |
904 | log_warning(msg.str()); | |
905 | } | |
906 | } | |
907 | ||
908 | ||
909 | /** | |
910 | * Failure while running update for service. | |
911 | * @param service Services' name. | |
912 | */ | |
913 | void Logger::print_update_service_failure(const std::string& service) const | |
914 | { | |
915 | if ( 0 <= Loglevel ) | |
916 | { | |
917 | ostringstream msg; | |
918 | msg << "Could not update service: " << service << endl; | |
919 | log_warning(msg.str()); | |
920 | } | |
921 | } | |
e304c27b BS |
922 | |
923 | ||
924 | /** | |
925 | * Starting shutdown | |
926 | */ | |
927 | void Logger::print_starting_shutdown() const | |
928 | { | |
929 | if ( 0 <= Loglevel ) | |
930 | { | |
931 | ostringstream msg; | |
932 | msg << "Shutting down ..." << endl; | |
933 | log_notice(msg.str()); | |
934 | } | |
935 | } | |
936 | ||
937 | ||
938 | /** | |
939 | * Shutdown complete | |
940 | */ | |
941 | void Logger::print_shutdown_succeeded() const | |
942 | { | |
943 | if ( 0 <= Loglevel ) | |
944 | { | |
945 | ostringstream msg; | |
946 | msg << "Shutting down complete ..." << endl; | |
947 | log_notice(msg.str()); | |
948 | } | |
949 | } | |
950 | ||
951 | ||
952 | /** | |
953 | * Shutdown parent succeeded | |
954 | */ | |
955 | void Logger::print_shutdown_parent_succeeded() const | |
956 | { | |
957 | if ( 0 <= Loglevel ) | |
958 | { | |
959 | ostringstream msg; | |
960 | msg << "Shutting down parent process completed ..." << endl; | |
961 | log_notice(msg.str()); | |
962 | } | |
963 | } | |
964 | ||
965 | ||
966 | /** | |
967 | * Starting shutdown parent | |
968 | */ | |
969 | void Logger::print_starting_shutdown_parent() const | |
970 | { | |
971 | if ( 0 <= Loglevel ) | |
972 | { | |
973 | ostringstream msg; | |
974 | msg << "Shutting down parent process ..." << endl; | |
975 | log_notice(msg.str()); | |
976 | } | |
977 | } |