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) |
cbbdeb6c | 28 | , ExternalWarningLevel(0) |
254bbf53 | 29 | { |
cbbdeb6c | 30 | set_log_facility(Loglevel,Syslog,ExternalWarningLog,ExternalWarningLevel); |
254bbf53 BS |
31 | } |
32 | ||
33 | ||
34 | /** | |
35 | * Default Destructor | |
36 | */ | |
37 | Logger::~Logger() | |
38 | { | |
254bbf53 BS |
39 | } |
40 | ||
41 | ||
42 | /** | |
59c8d63c BS |
43 | * Decides if Logging through syslog if enabled or through std. |
44 | * @param msg The message to log. | |
45 | */ | |
cbbdeb6c | 46 | void Logger::log_notice(const string& msg, int level) const |
59c8d63c BS |
47 | { |
48 | if ( Syslog ) | |
49 | syslog(LOG_NOTICE,msg.c_str()); | |
50 | else | |
27baf279 | 51 | cout << msg << endl;; |
59c8d63c BS |
52 | } |
53 | ||
54 | ||
55 | /** | |
56 | * Decides if Logging through syslog if enabled or through std. | |
57 | * @param msg The message to log. | |
58 | */ | |
cbbdeb6c | 59 | void Logger::log_warning(const string& msg, int level) const |
59c8d63c BS |
60 | { |
61 | if ( Syslog ) | |
62 | syslog(LOG_WARNING,msg.c_str()); | |
63 | else | |
27baf279 | 64 | cout << msg << endl; |
cbbdeb6c BS |
65 | |
66 | if ( (level <= ExternalWarningLevel) && (!ExternalWarningLog.empty()) ) | |
67 | { | |
68 | string external = ExternalWarningLog; | |
69 | external.append(" "); | |
efbde536 | 70 | external.append("\""); |
cbbdeb6c | 71 | external.append(msg); |
efbde536 | 72 | external.append("\""); |
cbbdeb6c | 73 | int ret_val = system(external.c_str()); |
a78b44b5 | 74 | // TODO: parse return code and error handling |
cbbdeb6c | 75 | } |
59c8d63c BS |
76 | } |
77 | ||
78 | ||
79 | /** | |
80 | * Decides if Logging through syslog if enabled or through std. | |
81 | * @param msg The message to log. | |
82 | */ | |
cbbdeb6c | 83 | void Logger::log_error(const string& msg, int level) const |
59c8d63c BS |
84 | { |
85 | if ( Syslog ) | |
86 | syslog(LOG_ERR,msg.c_str()); | |
87 | else | |
27baf279 | 88 | cerr << msg << endl; |
59c8d63c BS |
89 | } |
90 | ||
91 | ||
92 | /** | |
8bca3c5d BS |
93 | * Setter for member Loglevel. |
94 | * @param _loglevel Value to set Loglevel to. | |
95 | */ | |
96 | void Logger::set_loglevel(const int _loglevel) | |
97 | { | |
98 | Loglevel = _loglevel; | |
2e956a36 | 99 | cout << "Loglevel set" << endl; |
8bca3c5d BS |
100 | } |
101 | ||
102 | ||
103 | /** | |
104 | * Getter for member Loglevel. | |
105 | * @return Loglevel. | |
106 | */ | |
b38684ce | 107 | int Logger::get_loglevel() const |
8bca3c5d BS |
108 | { |
109 | return Loglevel; | |
110 | } | |
111 | ||
112 | ||
113 | /** | |
114 | * Setter for member Syslog. | |
115 | * @param _syslog Wether to log through syslog or not. | |
116 | */ | |
117 | void Logger::set_syslog(const bool _syslog) | |
118 | { | |
119 | Syslog = _syslog; | |
120 | } | |
121 | ||
122 | ||
123 | /** | |
124 | * Getter for member Syslog. | |
125 | * @return True if logging through syslog is enabled, false otherwise. | |
126 | */ | |
b38684ce | 127 | bool Logger::get_syslog() const |
8bca3c5d BS |
128 | { |
129 | return Syslog; | |
130 | } | |
131 | ||
132 | ||
133 | /** | |
134 | * Initialize the logging facility. | |
135 | */ | |
cbbdeb6c | 136 | void Logger::set_log_facility(const int _loglevel, const bool _syslog, const string& _external_error_log, const int _external_error_level) |
8bca3c5d BS |
137 | { |
138 | Loglevel = _loglevel; | |
139 | Syslog = _syslog; | |
cbbdeb6c BS |
140 | ExternalWarningLog = _external_error_log; |
141 | ExternalWarningLevel = _external_error_level; | |
142 | ||
8bca3c5d BS |
143 | |
144 | if ( Syslog ) | |
145 | openlog("bpdyndnsd",LOG_PID,LOG_DAEMON); | |
146 | } | |
147 | ||
148 | ||
149 | /** | |
254bbf53 BS |
150 | * Prints out the usage to the command line. |
151 | */ | |
b38684ce | 152 | void Logger::print_usage(const Options_descriptionPtr opt_desc) const |
254bbf53 | 153 | { |
cbbdeb6c BS |
154 | int level = 0; |
155 | if ( (level <= Loglevel) || ((level <= ExternalWarningLevel) && (!ExternalWarningLog.empty())) ) | |
59c8d63c BS |
156 | { |
157 | ostringstream msg; | |
158 | msg << "Usage: bpdyndnsd [Command line options]" << "\n" << endl; | |
159 | msg << *opt_desc << endl; | |
cbbdeb6c | 160 | log_notice(msg.str(),level); |
59c8d63c | 161 | } |
254bbf53 BS |
162 | } |
163 | ||
164 | ||
165 | /** | |
166 | * Prints out the programm name and the given version string on stdout. | |
167 | * @param version Version string. | |
168 | */ | |
b38684ce | 169 | void Logger::print_version() const |
254bbf53 | 170 | { |
cbbdeb6c BS |
171 | int level = 0; |
172 | if ( (level <= Loglevel) || ((level <= ExternalWarningLevel) && (!ExternalWarningLog.empty())) ) | |
59c8d63c BS |
173 | { |
174 | ostringstream msg; | |
175 | msg << "Bullet proof dynamic dns daemon.\nbpdyndnsd " << VERSION << "." << REVISION << "." << RELEASE << endl; | |
cbbdeb6c | 176 | log_notice(msg.str(),level); |
59c8d63c | 177 | } |
254bbf53 BS |
178 | } |
179 | ||
180 | ||
181 | /** | |
182 | * Prints out the successful parsing of the command line options. | |
183 | */ | |
b38684ce | 184 | void Logger::print_cmd_parsed() const |
254bbf53 | 185 | { |
cbbdeb6c BS |
186 | int level = 1; |
187 | if ( (level <= Loglevel) || ((level <= ExternalWarningLevel) && (!ExternalWarningLog.empty())) ) | |
59c8d63c BS |
188 | { |
189 | ostringstream msg; | |
190 | msg << "Command line options successfully parsed." << endl; | |
cbbdeb6c | 191 | log_notice(msg.str(),level); |
59c8d63c | 192 | } |
254bbf53 BS |
193 | } |
194 | ||
195 | ||
b38684ce | 196 | void Logger::print_conf_files_parsed() const |
667c672c | 197 | { |
cbbdeb6c BS |
198 | int level = 1; |
199 | if ( (level <= Loglevel) || ((level <= ExternalWarningLevel) && (!ExternalWarningLog.empty())) ) | |
667c672c BS |
200 | { |
201 | ostringstream msg; | |
202 | msg << "Config files successfully parsed." << endl; | |
cbbdeb6c | 203 | log_notice(msg.str(),level); |
667c672c BS |
204 | } |
205 | } | |
206 | ||
207 | ||
254bbf53 BS |
208 | /** |
209 | * Prints out the successful parsing of the config files. | |
daf2ea82 | 210 | * @param config_path The specified config path. |
254bbf53 | 211 | */ |
b38684ce | 212 | void Logger::print_conf_loaded(const string& config_path) const |
254bbf53 | 213 | { |
cbbdeb6c BS |
214 | int level = 1; |
215 | if ( (level <= Loglevel) || ((level <= ExternalWarningLevel) && (!ExternalWarningLog.empty())) ) | |
59c8d63c BS |
216 | { |
217 | ostringstream msg; | |
218 | msg << "Config files successfully loaded in: " << config_path << endl; | |
cbbdeb6c | 219 | log_notice(msg.str(),level); |
59c8d63c | 220 | } |
254bbf53 BS |
221 | } |
222 | ||
223 | ||
224 | /** | |
daf2ea82 BS |
225 | * Prints out the unsuccessful parsing of the config files. |
226 | * @param config_path The specified config path. | |
254bbf53 | 227 | */ |
b38684ce | 228 | void Logger::print_conf_not_loaded(const string& config_path) const |
254bbf53 | 229 | { |
cbbdeb6c BS |
230 | int level = 0; |
231 | if ( (level <= Loglevel) || ((level <= ExternalWarningLevel) && (!ExternalWarningLog.empty())) ) | |
59c8d63c BS |
232 | { |
233 | ostringstream msg; | |
234 | msg << "Config files couldn't be loaded in: " << config_path << endl; | |
cbbdeb6c | 235 | log_error(msg.str(),level); |
59c8d63c | 236 | } |
254bbf53 BS |
237 | } |
238 | ||
239 | ||
240 | /** | |
daf2ea82 BS |
241 | * A file could not be opened for reading. |
242 | * @param filename The filename. | |
254bbf53 | 243 | */ |
b38684ce | 244 | void Logger::print_error_opening_r(const string& filename) const |
254bbf53 | 245 | { |
cbbdeb6c BS |
246 | int level = 0; |
247 | if ( (level <= Loglevel) || ((level <= ExternalWarningLevel) && (!ExternalWarningLog.empty())) ) | |
59c8d63c BS |
248 | { |
249 | ostringstream msg; | |
250 | msg << "Error opening file for reading: " << filename << endl; | |
cbbdeb6c | 251 | log_error(msg.str(),level); |
59c8d63c | 252 | } |
254bbf53 BS |
253 | } |
254 | ||
255 | ||
256 | /** | |
667c672c BS |
257 | * A file could not be opened for writing. |
258 | * @param filename The filename. | |
259 | */ | |
b38684ce | 260 | void Logger::print_error_opening_rw(const string& filename) const |
667c672c | 261 | { |
cbbdeb6c BS |
262 | int level = 0; |
263 | if ( (level <= Loglevel) || ((level <= ExternalWarningLevel) && (!ExternalWarningLog.empty())) ) | |
667c672c BS |
264 | { |
265 | ostringstream msg; | |
266 | msg << "Error opening file for writing: " << filename << endl; | |
cbbdeb6c | 267 | log_error(msg.str(),level); |
667c672c BS |
268 | } |
269 | } | |
270 | ||
271 | ||
272 | /** | |
254bbf53 BS |
273 | * Desctructor of specified class was called. |
274 | * @param _class Name of the class. | |
275 | */ | |
b38684ce | 276 | void Logger::print_destructor_call(const string& _class) const |
254bbf53 | 277 | { |
cbbdeb6c BS |
278 | int level = 1; |
279 | if ( (level <= Loglevel) || ((level <= ExternalWarningLevel) && (!ExternalWarningLog.empty())) ) | |
59c8d63c BS |
280 | { |
281 | ostringstream msg; | |
282 | msg << "Destructor call: " << _class << endl; | |
cbbdeb6c | 283 | log_notice(msg.str(),level); |
59c8d63c | 284 | } |
254bbf53 BS |
285 | } |
286 | ||
287 | ||
288 | /** | |
289 | * Constructor of specified class was called. | |
290 | * @param _class Name of the class. | |
291 | */ | |
b38684ce | 292 | void Logger::print_constructor_call(const string& _class) const |
254bbf53 | 293 | { |
cbbdeb6c BS |
294 | int level = 1; |
295 | if ( (level <= Loglevel) || ((level <= ExternalWarningLevel) && (!ExternalWarningLog.empty())) ) | |
59c8d63c BS |
296 | { |
297 | ostringstream msg; | |
298 | msg << "Constructor call: " << _class << endl; | |
cbbdeb6c | 299 | log_notice(msg.str(),level); |
59c8d63c | 300 | } |
254bbf53 BS |
301 | } |
302 | ||
303 | ||
304 | /** | |
305 | * Update method for specified service was called. | |
daf2ea82 | 306 | * @param service The service for which is the update running. |
254bbf53 | 307 | */ |
b38684ce | 308 | void Logger::print_update_service(const string& service) const |
254bbf53 | 309 | { |
cbbdeb6c BS |
310 | int level = 0; |
311 | if ( (level <= Loglevel) || ((level <= ExternalWarningLevel) && (!ExternalWarningLog.empty())) ) | |
59c8d63c BS |
312 | { |
313 | ostringstream msg; | |
314 | msg << "Running update for service: " << service << endl; | |
cbbdeb6c | 315 | log_notice(msg.str(),level); |
59c8d63c | 316 | } |
254bbf53 BS |
317 | } |
318 | ||
319 | ||
daf2ea82 BS |
320 | /** |
321 | * An unknown option on the command line was detected. | |
322 | * @param unknown_option The unknown option. | |
323 | */ | |
b38684ce | 324 | void Logger::print_unknown_cmd_option(const string& unknown_option) const |
254bbf53 | 325 | { |
cbbdeb6c BS |
326 | int level = 0; |
327 | if ( (level <= Loglevel) || ((level <= ExternalWarningLevel) && (!ExternalWarningLog.empty())) ) | |
59c8d63c BS |
328 | { |
329 | ostringstream msg; | |
330 | msg << "Unknown option on command line detected: " << unknown_option << endl; | |
cbbdeb6c | 331 | log_error(msg.str(),level); |
59c8d63c | 332 | } |
254bbf53 BS |
333 | } |
334 | ||
335 | ||
daf2ea82 BS |
336 | /** |
337 | * An unknown protocol was specified. | |
338 | * @param protocol The unknown protocol. | |
339 | */ | |
b38684ce | 340 | void Logger::print_unknown_protocol(const string& protocol) const |
254bbf53 | 341 | { |
cbbdeb6c BS |
342 | int level = 0; |
343 | if ( (level <= Loglevel) || ((level <= ExternalWarningLevel) && (!ExternalWarningLog.empty())) ) | |
59c8d63c BS |
344 | { |
345 | ostringstream msg; | |
346 | msg << "Unknown protocol defined: " << protocol << endl; | |
cbbdeb6c | 347 | log_error(msg.str(),level); |
59c8d63c | 348 | } |
254bbf53 BS |
349 | } |
350 | ||
351 | ||
daf2ea82 BS |
352 | /** |
353 | * Loading a service config file. | |
354 | * @param filename The service config file. | |
355 | */ | |
b38684ce | 356 | void Logger::print_load_service_conf(const string& filename) const |
254bbf53 | 357 | { |
cbbdeb6c BS |
358 | int level = 1; |
359 | if ( (level <= Loglevel) || ((level <= ExternalWarningLevel) && (!ExternalWarningLog.empty())) ) | |
59c8d63c BS |
360 | { |
361 | ostringstream msg; | |
362 | msg << "Loading service config file: " << filename << endl; | |
cbbdeb6c | 363 | log_notice(msg.str(),level); |
59c8d63c | 364 | } |
254bbf53 BS |
365 | } |
366 | ||
367 | ||
daf2ea82 BS |
368 | /** |
369 | * Loading the main config file. | |
370 | * @param filename The main config file. | |
371 | */ | |
b38684ce | 372 | void Logger::print_load_main_conf(const string& filename) const |
254bbf53 | 373 | { |
cbbdeb6c BS |
374 | int level = 1; |
375 | if ( (level <= Loglevel) || ((level <= ExternalWarningLevel) && (!ExternalWarningLog.empty())) ) | |
59c8d63c BS |
376 | { |
377 | ostringstream msg; | |
378 | msg << "Loading main config file: " << filename << endl; | |
cbbdeb6c | 379 | log_notice(msg.str(),level); |
59c8d63c | 380 | } |
254bbf53 BS |
381 | } |
382 | ||
383 | ||
daf2ea82 BS |
384 | /** |
385 | * There is an unknown option in a service config file. | |
386 | * @param unknown_option The unknown option. | |
387 | */ | |
8a00a649 | 388 | void Logger::print_unknown_service_conf_option(const string& service_conf_file, const string& unknown_option) const |
254bbf53 | 389 | { |
cbbdeb6c BS |
390 | int level = 0; |
391 | if ( (level <= Loglevel) || ((level <= ExternalWarningLevel) && (!ExternalWarningLog.empty())) ) | |
59c8d63c BS |
392 | { |
393 | ostringstream msg; | |
8a00a649 | 394 | msg << "Unknown option in service config file detected: " << service_conf_file << " Unknown option: " << unknown_option << endl; |
cbbdeb6c | 395 | log_error(msg.str(),level); |
59c8d63c | 396 | } |
254bbf53 BS |
397 | } |
398 | ||
399 | ||
daf2ea82 BS |
400 | /** |
401 | * There is an unknown option in the main config file. | |
402 | * @param unknown_option The unknown option. | |
403 | */ | |
b38684ce | 404 | void Logger::print_unknown_main_conf_option(const string& unknown_option) const |
254bbf53 | 405 | { |
cbbdeb6c BS |
406 | int level = 0; |
407 | if ( (level <= Loglevel) || ((level <= ExternalWarningLevel) && (!ExternalWarningLog.empty())) ) | |
59c8d63c BS |
408 | { |
409 | ostringstream msg; | |
410 | msg << "Unknown option in main config file detected: " << unknown_option << endl; | |
cbbdeb6c | 411 | log_error(msg.str(),level); |
59c8d63c | 412 | } |
254bbf53 BS |
413 | } |
414 | ||
415 | ||
daf2ea82 BS |
416 | /** |
417 | * The defined config path doesn't exist or is not a directory. | |
418 | * @param config_path The defined config path. | |
419 | */ | |
b38684ce | 420 | void Logger::print_error_config_path(const string& config_path) const |
254bbf53 | 421 | { |
cbbdeb6c BS |
422 | int level = 0; |
423 | if ( (level <= Loglevel) || ((level <= ExternalWarningLevel) && (!ExternalWarningLog.empty())) ) | |
59c8d63c BS |
424 | { |
425 | ostringstream msg; | |
426 | msg << "Config path doesn't exists or is not a diretory: " << config_path << endl; | |
cbbdeb6c | 427 | log_error(msg.str(),level); |
59c8d63c | 428 | } |
254bbf53 BS |
429 | } |
430 | ||
431 | ||
daf2ea82 BS |
432 | /** |
433 | * There is a missing command line option to initialize a service object. | |
434 | */ | |
b38684ce | 435 | void Logger::print_missing_cmd_service_option() const |
254bbf53 | 436 | { |
cbbdeb6c BS |
437 | int level = 0; |
438 | if ( (level <= Loglevel) || ((level <= ExternalWarningLevel) && (!ExternalWarningLog.empty())) ) | |
59c8d63c BS |
439 | { |
440 | ostringstream msg; | |
441 | msg << "Missing option to initialize service. Protocol, host, login and password must be specified." << endl; | |
cbbdeb6c | 442 | log_error(msg.str(),level); |
59c8d63c | 443 | } |
254bbf53 | 444 | } |
388f4ab0 BS |
445 | |
446 | ||
c5675c01 | 447 | /** |
8a00a649 BS |
448 | * Missing option in service config file. |
449 | * @param service_conf_file Service config file | |
450 | */ | |
451 | void Logger::print_missing_service_conf_option(const string& service_conf_file) const | |
452 | { | |
cbbdeb6c BS |
453 | int level = 0; |
454 | if ( (level <= Loglevel) || ((level <= ExternalWarningLevel) && (!ExternalWarningLog.empty())) ) | |
8a00a649 BS |
455 | { |
456 | ostringstream msg; | |
457 | msg << "Missing option in service config file " << service_conf_file << " to initialize service. Protocol, host, login and password must be specified." << endl; | |
cbbdeb6c | 458 | log_error(msg.str(),level); |
8a00a649 BS |
459 | } |
460 | } | |
461 | ||
462 | ||
463 | /** | |
c5675c01 BS |
464 | * Process running as daemon. |
465 | * @param pid The pid of the daemon. | |
466 | */ | |
b38684ce | 467 | void Logger::print_runnig_as_daemon(const int pid) const |
388f4ab0 | 468 | { |
cbbdeb6c BS |
469 | int level = 1; |
470 | if ( (level <= Loglevel) || ((level <= ExternalWarningLevel) && (!ExternalWarningLog.empty())) ) | |
59c8d63c BS |
471 | { |
472 | ostringstream msg; | |
473 | msg << "Runnig as daemon: " << pid << endl; | |
cbbdeb6c | 474 | log_notice(msg.str(),level); |
59c8d63c | 475 | } |
388f4ab0 BS |
476 | } |
477 | ||
c5675c01 BS |
478 | |
479 | /** | |
480 | * Prints out the daemon mode. | |
481 | * @param daemon_mode The daemon mode. | |
482 | */ | |
b38684ce | 483 | void Logger::print_daemon_mode(const bool daemon_mode) const |
388f4ab0 | 484 | { |
cbbdeb6c BS |
485 | int level = 1; |
486 | if ( (level <= Loglevel) || ((level <= ExternalWarningLevel) && (!ExternalWarningLog.empty())) ) | |
59c8d63c BS |
487 | { |
488 | string mode = "disabled"; | |
489 | if (daemon_mode == true) | |
490 | mode = "enabled"; | |
491 | ostringstream msg; | |
492 | msg << "Daemon mode is " << mode << "." << endl; | |
cbbdeb6c | 493 | log_notice(msg.str(),level); |
59c8d63c | 494 | } |
388f4ab0 BS |
495 | } |
496 | ||
497 | ||
c5675c01 BS |
498 | /** |
499 | * There was an error while trying to fork. | |
500 | */ | |
b38684ce | 501 | void Logger::print_error_fork() const |
388f4ab0 | 502 | { |
cbbdeb6c BS |
503 | int level = 0; |
504 | if ( (level <= Loglevel) || ((level <= ExternalWarningLevel) && (!ExternalWarningLog.empty())) ) | |
59c8d63c BS |
505 | { |
506 | ostringstream msg; | |
507 | msg << "Error while trying to fork." << endl; | |
cbbdeb6c | 508 | log_notice(msg.str(),level); |
59c8d63c | 509 | } |
388f4ab0 BS |
510 | } |
511 | ||
512 | ||
c5675c01 BS |
513 | /** |
514 | * A pid in the pidfile was found. | |
515 | * @param pid The pid found in the pidfile. | |
516 | */ | |
b38684ce | 517 | void Logger::print_pid_found(const int pid) const |
388f4ab0 | 518 | { |
cbbdeb6c BS |
519 | int level = 1; |
520 | if ( (level <= Loglevel) || ((level <= ExternalWarningLevel) && (!ExternalWarningLog.empty())) ) | |
59c8d63c BS |
521 | { |
522 | ostringstream msg; | |
523 | msg << "Pidfile found: " << pid << ". Checking if process is still runnig..." << endl; | |
cbbdeb6c | 524 | log_notice(msg.str(),level); |
59c8d63c | 525 | } |
388f4ab0 BS |
526 | } |
527 | ||
528 | ||
c5675c01 BS |
529 | /** |
530 | * Another process is already running. | |
531 | * @param pid The pid of the other process. | |
532 | */ | |
b38684ce | 533 | void Logger::print_process_already_running(const int pid) const |
388f4ab0 | 534 | { |
cbbdeb6c BS |
535 | int level = 0; |
536 | if ( (level <= Loglevel) || ((level <= ExternalWarningLevel) && (!ExternalWarningLog.empty())) ) | |
59c8d63c BS |
537 | { |
538 | ostringstream msg; | |
539 | msg << "Another bpdyndnsd process with PID " << pid << " is already running!" << endl; | |
cbbdeb6c | 540 | log_error(msg.str(),level); |
59c8d63c | 541 | } |
388f4ab0 | 542 | } |
c5675c01 BS |
543 | |
544 | ||
545 | /** | |
546 | * SIGTERM caught. | |
547 | */ | |
b38684ce | 548 | void Logger::print_caught_sigterm() const |
c5675c01 | 549 | { |
cbbdeb6c BS |
550 | int level = 0; |
551 | if ( (level <= Loglevel) || ((level <= ExternalWarningLevel) && (!ExternalWarningLog.empty())) ) | |
59c8d63c BS |
552 | { |
553 | ostringstream msg; | |
554 | msg << "Caught SIGTERM. Exiting..." << endl; | |
cbbdeb6c | 555 | log_notice(msg.str(),level); |
59c8d63c | 556 | } |
c5675c01 BS |
557 | } |
558 | ||
559 | ||
560 | /** | |
561 | * SIGUSR1 caught. | |
562 | */ | |
b38684ce | 563 | void Logger::print_caught_siguser1() const |
c5675c01 | 564 | { |
cbbdeb6c BS |
565 | int level = 0; |
566 | if ( (level <= Loglevel) || ((level <= ExternalWarningLevel) && (!ExternalWarningLog.empty())) ) | |
59c8d63c BS |
567 | { |
568 | ostringstream msg; | |
569 | msg << "Caught SIGUSR1. Switching to offline mode..." << endl; | |
cbbdeb6c | 570 | log_notice(msg.str(),level); |
59c8d63c | 571 | } |
c5675c01 BS |
572 | } |
573 | ||
574 | ||
575 | /** | |
576 | * SIGHUP caught. | |
577 | */ | |
b38684ce | 578 | void Logger::print_caught_sighup() const |
c5675c01 | 579 | { |
cbbdeb6c BS |
580 | int level = 1; |
581 | if ( (level <= Loglevel) || ((level <= ExternalWarningLevel) && (!ExternalWarningLog.empty())) ) | |
59c8d63c BS |
582 | { |
583 | ostringstream msg; | |
584 | msg << "Caught SIGHUP. Reloading config and switching to online mode..." << endl; | |
cbbdeb6c | 585 | log_notice(msg.str(),level); |
59c8d63c | 586 | } |
c5675c01 | 587 | } |
8bca3c5d BS |
588 | |
589 | ||
590 | /** | |
591 | * Error while setting signal handler. | |
592 | */ | |
b38684ce | 593 | void Logger::print_error_setting_signal(const string& signal) const |
8bca3c5d | 594 | { |
cbbdeb6c BS |
595 | int level = 0; |
596 | if ( (level <= Loglevel) || ((level <= ExternalWarningLevel) && (!ExternalWarningLog.empty())) ) | |
59c8d63c BS |
597 | { |
598 | ostringstream msg; | |
667c672c | 599 | msg << "Error while setting signal handler for: " << signal << endl; |
cbbdeb6c | 600 | log_error(msg.str(),level); |
59c8d63c | 601 | } |
8bca3c5d BS |
602 | } |
603 | ||
604 | ||
605 | /** | |
606 | * Error while setting signal handler. | |
607 | */ | |
b38684ce | 608 | void Logger::print_init_log_facility() const |
8bca3c5d | 609 | { |
cbbdeb6c BS |
610 | int level = 1; |
611 | if ( (level <= Loglevel) || ((level <= ExternalWarningLevel) && (!ExternalWarningLog.empty())) ) | |
59c8d63c BS |
612 | { |
613 | ostringstream msg; | |
614 | msg << "Initialized logging facility." << " Loglevel: " << Loglevel << " Syslog: " << Syslog << endl; | |
cbbdeb6c | 615 | log_notice(msg.str(),level); |
59c8d63c | 616 | } |
8bca3c5d BS |
617 | } |
618 | ||
27baf279 | 619 | |
8bca3c5d BS |
620 | /** |
621 | * Be verbose. Currently we are in offline mode. | |
622 | */ | |
b38684ce | 623 | void Logger::print_offline_mode() const |
8bca3c5d | 624 | { |
cbbdeb6c BS |
625 | int level = 0; |
626 | if ( (level <= Loglevel) || ((level <= ExternalWarningLevel) && (!ExternalWarningLog.empty())) ) | |
59c8d63c BS |
627 | { |
628 | ostringstream msg; | |
629 | msg << "Offline mode..." << endl; | |
cbbdeb6c | 630 | log_notice(msg.str(),level); |
59c8d63c | 631 | } |
8bca3c5d | 632 | } |
27baf279 BS |
633 | |
634 | ||
635 | /** | |
636 | * Objects successfully serialized. | |
637 | */ | |
b38684ce | 638 | void Logger::print_serialized_objects_success() const |
27baf279 | 639 | { |
cbbdeb6c BS |
640 | int level = 1; |
641 | if ( (level <= Loglevel) || ((level <= ExternalWarningLevel) && (!ExternalWarningLog.empty())) ) | |
27baf279 BS |
642 | { |
643 | ostringstream msg; | |
644 | msg << "Serialized objects successfully." << endl; | |
cbbdeb6c | 645 | log_notice(msg.str(),level); |
27baf279 BS |
646 | } |
647 | } | |
648 | ||
649 | ||
650 | /** | |
651 | * Objects successfully de-serialized. | |
652 | */ | |
b38684ce | 653 | void Logger::print_deserialized_objects_success() const |
27baf279 | 654 | { |
cbbdeb6c BS |
655 | int level = 1; |
656 | if ( (level <= Loglevel) || ((level <= ExternalWarningLevel) && (!ExternalWarningLog.empty())) ) | |
27baf279 BS |
657 | { |
658 | ostringstream msg; | |
659 | msg << "De-serialized objects successfully." << endl; | |
cbbdeb6c | 660 | log_notice(msg.str(),level); |
27baf279 BS |
661 | } |
662 | } | |
663 | ||
664 | ||
5d38cfe6 BS |
665 | /** |
666 | * Prints out the content of a service object. | |
667 | * @param message Message to be added on output first. | |
668 | * @param protocol Service's protocol. | |
669 | * @param hostname Service's hostname. | |
670 | * @param login Service's login. | |
671 | * @param password Service's password. | |
672 | * @param actual_ip Service's actual_ip. | |
673 | * @param lastupdated Service's lastupdated. | |
674 | */ | |
d5a516ba | 675 | 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<int>* lastupdated) const |
27baf279 | 676 | { |
cbbdeb6c BS |
677 | int level = 1; |
678 | if ( (level <= Loglevel) || ((level <= ExternalWarningLevel) && (!ExternalWarningLog.empty())) ) | |
27baf279 BS |
679 | { |
680 | ostringstream msg; | |
681 | msg << message << endl; | |
3c0cd271 BS |
682 | msg << "\t" << "Protocol: " << protocol << endl; |
683 | msg << "\t" << "Hostname: " << hostname << endl; | |
684 | msg << "\t" << "Login: " << login << endl; | |
685 | msg << "\t" << "Password: " << password << endl; | |
686 | msg << "\t" << "Update Interval: " << update_interval << endl; | |
687 | msg << "\t" << "Max Updates: " << max_updates_within_interval << endl; | |
d5a516ba | 688 | msg << "\t" << "DNS Cache TTL: " << dns_cache_ttl << endl; |
3c0cd271 BS |
689 | msg << "\t" << "Actual_IP: " << actual_ip << endl; |
690 | BOOST_FOREACH( int update_time, *lastupdated) | |
691 | { | |
692 | msg << "\t" << "Lastupdated: " << update_time << endl; | |
693 | } | |
cbbdeb6c | 694 | log_notice(msg.str(),level); |
27baf279 BS |
695 | } |
696 | } | |
5d38cfe6 BS |
697 | |
698 | ||
699 | /** | |
700 | * Caught exception while serialize. | |
701 | * @param exception Exception message. | |
702 | */ | |
b38684ce | 703 | void Logger::print_exception_serialize(const string& exception) const |
5d38cfe6 | 704 | { |
cbbdeb6c BS |
705 | int level = 0; |
706 | if ( (level <= Loglevel) || ((level <= ExternalWarningLevel) && (!ExternalWarningLog.empty())) ) | |
667c672c BS |
707 | { |
708 | ostringstream msg; | |
709 | msg << "Error while trying to serialize Serviceholder object: " << exception << endl; | |
cbbdeb6c | 710 | log_error(msg.str(),level); |
667c672c BS |
711 | } |
712 | } | |
713 | ||
714 | ||
715 | /** | |
716 | * Caught exception while de-serialize. | |
717 | * @param exception Exception message. | |
718 | */ | |
e8d4a6f8 | 719 | void Logger::print_exception_deserialize(const string& exception) const |
667c672c | 720 | { |
cbbdeb6c BS |
721 | int level = 0; |
722 | if ( (level <= Loglevel) || ((level <= ExternalWarningLevel) && (!ExternalWarningLog.empty())) ) | |
667c672c BS |
723 | { |
724 | ostringstream msg; | |
725 | msg << "Error while trying to de-serialize Serviceholder object: " << exception << endl; | |
cbbdeb6c | 726 | log_error(msg.str(),level); |
667c672c BS |
727 | } |
728 | } | |
729 | ||
730 | ||
731 | /** | |
732 | * Child couldn't be killed by parent. | |
733 | * @param pid Pid of the child. | |
734 | */ | |
b38684ce | 735 | void Logger::print_error_kill_child(const int pid) const |
667c672c | 736 | { |
cbbdeb6c BS |
737 | int level = 0; |
738 | if ( (level <= Loglevel) || ((level <= ExternalWarningLevel) && (!ExternalWarningLog.empty())) ) | |
667c672c BS |
739 | { |
740 | ostringstream msg; | |
741 | msg << "Could not kill child process with PID: " << pid << endl; | |
cbbdeb6c | 742 | log_error(msg.str(),level); |
667c672c BS |
743 | } |
744 | } | |
745 | ||
746 | ||
0665b239 BS |
747 | /** |
748 | * Child was killed by parent because of error. | |
749 | * @param pid The pid (child) killed. | |
750 | */ | |
b38684ce | 751 | void Logger::print_child_killed(const int pid) const |
584b9407 | 752 | { |
cbbdeb6c BS |
753 | int level = 1; |
754 | if ( (level <= Loglevel) || ((level <= ExternalWarningLevel) && (!ExternalWarningLog.empty())) ) | |
584b9407 BS |
755 | { |
756 | ostringstream msg; | |
757 | msg << "Killed child process with PID: " << pid << endl; | |
cbbdeb6c | 758 | log_notice(msg.str(),level); |
584b9407 BS |
759 | } |
760 | } | |
761 | ||
762 | ||
667c672c BS |
763 | /** |
764 | * There is no object file. | |
765 | * @param object_file The object file. | |
766 | */ | |
e8d4a6f8 | 767 | void Logger::print_no_object_file(const string& object_file) const |
667c672c | 768 | { |
cbbdeb6c BS |
769 | int level = 1; |
770 | if ( (level <= Loglevel) || ((level <= ExternalWarningLevel) && (!ExternalWarningLog.empty())) ) | |
667c672c BS |
771 | { |
772 | ostringstream msg; | |
773 | msg << "There is no object file: " << object_file << ". Continue without recovering state from old services!" << endl; | |
cbbdeb6c | 774 | log_warning(msg.str(),level); |
667c672c | 775 | } |
5d38cfe6 | 776 | } |
0665b239 BS |
777 | |
778 | ||
779 | /** | |
780 | * Prints out the given hostname | |
781 | * @param hostname Hostname as string. | |
782 | */ | |
e8d4a6f8 | 783 | void Logger::print_hostname(const string& hostname) const |
0665b239 | 784 | { |
cbbdeb6c BS |
785 | int level = 1; |
786 | if ( (level <= Loglevel) || ((level <= ExternalWarningLevel) && (!ExternalWarningLog.empty())) ) | |
0665b239 BS |
787 | { |
788 | ostringstream msg; | |
789 | msg << "Detected following hostname of localhost: " << hostname << endl; | |
cbbdeb6c | 790 | log_notice(msg.str(),level); |
0665b239 BS |
791 | } |
792 | } | |
793 | ||
794 | ||
795 | /** | |
019dc0d9 | 796 | * Prints out the detected own ipv4 address |
0665b239 BS |
797 | * @param ip_addr String representation of the detected ip. |
798 | */ | |
c3dea5dc | 799 | void Logger::print_own_ipv4(const string& ip_addr_v4, const string& hostname) const |
0665b239 | 800 | { |
cbbdeb6c BS |
801 | int level = 1; |
802 | if ( (level <= Loglevel) || ((level <= ExternalWarningLevel) && (!ExternalWarningLog.empty())) ) | |
0665b239 BS |
803 | { |
804 | ostringstream msg; | |
c3dea5dc | 805 | msg << "Detected following IPv4-Address of host: " << hostname << " : " << ip_addr_v4 << endl; |
cbbdeb6c | 806 | log_notice(msg.str(),level); |
019dc0d9 BS |
807 | } |
808 | } | |
809 | ||
810 | ||
811 | /** | |
812 | * Prints out the detected own ipv5 address | |
813 | * @param ip_addr String representation of the detected ip. | |
814 | */ | |
c3dea5dc | 815 | void Logger::print_own_ipv6(const string& ip_addr_v6, const string& hostname) const |
019dc0d9 | 816 | { |
cbbdeb6c BS |
817 | int level = 1; |
818 | if ( (level <= Loglevel) || ((level <= ExternalWarningLevel) && (!ExternalWarningLog.empty())) ) | |
019dc0d9 BS |
819 | { |
820 | ostringstream msg; | |
c3dea5dc | 821 | msg << "Detected following IPv6-Address of host: " << hostname << " : " << ip_addr_v6 << endl; |
cbbdeb6c | 822 | log_notice(msg.str(),level); |
0665b239 BS |
823 | } |
824 | } | |
825 | ||
826 | ||
827 | /** | |
828 | * Exception while trying to resolve hostname to ip. | |
829 | * @param exception The exception caught. | |
830 | * @param hostname The hostname. | |
831 | */ | |
1c0908b5 | 832 | void Logger::print_error_hostname_to_ip(const string& exception, const string& hostname) const |
0665b239 | 833 | { |
a03fb896 | 834 | int level = 0; |
cbbdeb6c | 835 | if ( (level <= Loglevel) || ((level <= ExternalWarningLevel) && (!ExternalWarningLog.empty())) ) |
0665b239 BS |
836 | { |
837 | ostringstream msg; | |
c3dea5dc | 838 | msg << "Could not resolve the hostname: " << hostname << " to an IP-Address: " << exception << endl; |
cbbdeb6c | 839 | log_error(msg.str(),level); |
0665b239 BS |
840 | } |
841 | } | |
68c6b4af BS |
842 | |
843 | ||
1c0908b5 BS |
844 | /** |
845 | * The update of the given service was successful. | |
846 | * @param service The service. | |
847 | */ | |
848 | void Logger::print_update_service_successful(const string& service) const | |
68c6b4af | 849 | { |
cbbdeb6c BS |
850 | int level = 0; |
851 | if ( (level <= Loglevel) || ((level <= ExternalWarningLevel) && (!ExternalWarningLog.empty())) ) | |
68c6b4af BS |
852 | { |
853 | ostringstream msg; | |
854 | msg << "Updated service successful: " << service << endl; | |
cbbdeb6c | 855 | log_notice(msg.str(),level); |
1c0908b5 BS |
856 | } |
857 | } | |
858 | ||
859 | ||
860 | /** | |
861 | * No ip could be determined through webcheck | |
862 | */ | |
863 | void Logger::print_webcheck_no_ip() const | |
864 | { | |
cbbdeb6c BS |
865 | int level = 0; |
866 | if ( (level <= Loglevel) || ((level <= ExternalWarningLevel) && (!ExternalWarningLog.empty())) ) | |
1c0908b5 BS |
867 | { |
868 | ostringstream msg; | |
efbde536 | 869 | msg << "IP-Address of this host could not be determined through any configured webcheck url." << endl; |
cbbdeb6c | 870 | log_warning(msg.str(),level); |
1c0908b5 BS |
871 | } |
872 | } | |
873 | ||
874 | ||
875 | /** | |
876 | * Connection problem while trying to get ip through webcheck url | |
877 | * @param curl_err_buff Curl error message | |
878 | * @param url the url | |
879 | */ | |
880 | void Logger::print_webcheck_url_connection_problem(const char * curl_err_buff, const string& url) const | |
881 | { | |
cbbdeb6c BS |
882 | int level = 1; |
883 | if ( (level <= Loglevel) || ((level <= ExternalWarningLevel) && (!ExternalWarningLog.empty())) ) | |
1c0908b5 BS |
884 | { |
885 | ostringstream msg; | |
886 | msg << "There was a problem while trying to connect to following URL: " << url << " CURL error: " << curl_err_buff << endl; | |
cbbdeb6c | 887 | log_warning(msg.str(),level); |
1c0908b5 BS |
888 | } |
889 | } | |
890 | ||
891 | ||
892 | /** | |
893 | * Prints out curl error. | |
894 | * @param curl_err_buff Curl error message. | |
895 | * @param url URL | |
896 | */ | |
897 | void Logger::print_webcheck_error(const char * curl_err_buff, const string& url) const | |
898 | { | |
cbbdeb6c BS |
899 | int level = 0; |
900 | if ( (level <= Loglevel) || ((level <= ExternalWarningLevel) && (!ExternalWarningLog.empty())) ) | |
1c0908b5 BS |
901 | { |
902 | ostringstream msg; | |
903 | msg << "There was an error while trying to connect to following URL: " << url << " CURL error: " << curl_err_buff << endl; | |
cbbdeb6c | 904 | log_error(msg.str(),level); |
68c6b4af BS |
905 | } |
906 | } | |
1c0908b5 BS |
907 | |
908 | ||
909 | /** | |
910 | * Prints out the received data through curl. | |
911 | * @param curl_data Data string | |
912 | */ | |
913 | void Logger::print_received_curl_data(const string& curl_data) const | |
914 | { | |
cbbdeb6c BS |
915 | int level = 1; |
916 | if ( (level <= Loglevel) || ((level <= ExternalWarningLevel) && (!ExternalWarningLog.empty())) ) | |
1c0908b5 BS |
917 | { |
918 | ostringstream msg; | |
919 | msg << "Received CURL data: " << curl_data << endl; | |
cbbdeb6c | 920 | log_notice(msg.str(),level); |
1c0908b5 BS |
921 | } |
922 | } | |
923 | ||
924 | ||
925 | /** | |
926 | * IP was foudn through regex | |
927 | * @param ip The IP found. | |
928 | */ | |
929 | void Logger::print_regex_found_ip(const string& ip) const | |
930 | { | |
cbbdeb6c BS |
931 | int level = 1; |
932 | if ( (level <= Loglevel) || ((level <= ExternalWarningLevel) && (!ExternalWarningLog.empty())) ) | |
1c0908b5 BS |
933 | { |
934 | ostringstream msg; | |
935 | msg << "Found IP-Address via regex: " << ip << endl; | |
cbbdeb6c | 936 | log_notice(msg.str(),level); |
1c0908b5 BS |
937 | } |
938 | } | |
939 | ||
940 | ||
941 | /** | |
942 | * No IP was found through regex. | |
943 | * @param data The data string which should contain a valid IP.s | |
944 | */ | |
945 | void Logger::print_regex_ip_not_found(const string& data) const | |
946 | { | |
efbde536 | 947 | int level = 1; |
cbbdeb6c | 948 | if ( (level <= Loglevel) || ((level <= ExternalWarningLevel) && (!ExternalWarningLog.empty())) ) |
1c0908b5 BS |
949 | { |
950 | ostringstream msg; | |
951 | msg << "Could not extract an IP-Address via regex from following data:\n" << data << endl; | |
cbbdeb6c | 952 | log_warning(msg.str(),level); |
1c0908b5 BS |
953 | } |
954 | } | |
3c0cd271 BS |
955 | |
956 | ||
957 | /** | |
958 | * Detected multiple occurrences of the same option. | |
959 | * @param message Error message. | |
960 | */ | |
961 | void Logger::print_multiple_cmd_option(const string& message) const | |
962 | { | |
cbbdeb6c BS |
963 | int level = 0; |
964 | if ( (level <= Loglevel) || ((level <= ExternalWarningLevel) && (!ExternalWarningLog.empty())) ) | |
3c0cd271 BS |
965 | { |
966 | ostringstream msg; | |
967 | msg << "The same option is only allowed once: " << message << endl; | |
cbbdeb6c | 968 | log_error(msg.str(),level); |
3c0cd271 BS |
969 | } |
970 | } | |
971 | ||
972 | ||
973 | /** | |
974 | * An update would exceed the update interval. Prints out a warning message. | |
975 | * @param current_time Current time. | |
976 | * @param old_time Time of update #MaxUpdatesWithinInterval ago. | |
977 | * @param MaxUpdatesWithinInterval Number of allowed updates in one update interval. | |
978 | * @param service The service which exceeds update interval. | |
979 | */ | |
980 | void Logger::print_update_not_allowed(const int current_time, const int old_time, const int MaxUpdatesWithinInterval, const string& service) const | |
981 | { | |
efbde536 | 982 | int level = 1; |
cbbdeb6c | 983 | if ( (level <= Loglevel) || ((level <= ExternalWarningLevel) && (!ExternalWarningLog.empty())) ) |
3c0cd271 BS |
984 | { |
985 | ostringstream msg; | |
986 | 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; | |
cbbdeb6c | 987 | log_warning(msg.str(),level); |
3c0cd271 BS |
988 | } |
989 | } | |
990 | ||
991 | ||
992 | /** | |
993 | * Failure while running update for service. | |
994 | * @param service Services' name. | |
995 | */ | |
e8d4a6f8 | 996 | void Logger::print_update_service_failure(const string& service) const |
3c0cd271 | 997 | { |
cbbdeb6c BS |
998 | int level = 0; |
999 | if ( (level <= Loglevel) || ((level <= ExternalWarningLevel) && (!ExternalWarningLog.empty())) ) | |
3c0cd271 BS |
1000 | { |
1001 | ostringstream msg; | |
1002 | msg << "Could not update service: " << service << endl; | |
cbbdeb6c | 1003 | log_warning(msg.str(),level); |
3c0cd271 BS |
1004 | } |
1005 | } | |
e304c27b BS |
1006 | |
1007 | ||
1008 | /** | |
1009 | * Starting shutdown | |
1010 | */ | |
1011 | void Logger::print_starting_shutdown() const | |
1012 | { | |
cbbdeb6c BS |
1013 | int level = 0; |
1014 | if ( (level <= Loglevel) || ((level <= ExternalWarningLevel) && (!ExternalWarningLog.empty())) ) | |
e304c27b BS |
1015 | { |
1016 | ostringstream msg; | |
1017 | msg << "Shutting down ..." << endl; | |
cbbdeb6c | 1018 | log_notice(msg.str(),level); |
e304c27b BS |
1019 | } |
1020 | } | |
1021 | ||
1022 | ||
1023 | /** | |
1024 | * Shutdown complete | |
1025 | */ | |
1026 | void Logger::print_shutdown_succeeded() const | |
1027 | { | |
cbbdeb6c BS |
1028 | int level = 0; |
1029 | if ( (level <= Loglevel) || ((level <= ExternalWarningLevel) && (!ExternalWarningLog.empty())) ) | |
e304c27b BS |
1030 | { |
1031 | ostringstream msg; | |
1032 | msg << "Shutting down complete ..." << endl; | |
cbbdeb6c | 1033 | log_notice(msg.str(),level); |
e304c27b BS |
1034 | } |
1035 | } | |
1036 | ||
1037 | ||
1038 | /** | |
1039 | * Shutdown parent succeeded | |
1040 | */ | |
1041 | void Logger::print_shutdown_parent_succeeded() const | |
1042 | { | |
cbbdeb6c BS |
1043 | int level = 0; |
1044 | if ( (level <= Loglevel) || ((level <= ExternalWarningLevel) && (!ExternalWarningLog.empty())) ) | |
e304c27b BS |
1045 | { |
1046 | ostringstream msg; | |
1047 | msg << "Shutting down parent process completed ..." << endl; | |
cbbdeb6c | 1048 | log_notice(msg.str(),level); |
e304c27b BS |
1049 | } |
1050 | } | |
1051 | ||
1052 | ||
1053 | /** | |
1054 | * Starting shutdown parent | |
1055 | */ | |
1056 | void Logger::print_starting_shutdown_parent() const | |
1057 | { | |
cbbdeb6c BS |
1058 | int level = 0; |
1059 | if ( (level <= Loglevel) || ((level <= ExternalWarningLevel) && (!ExternalWarningLog.empty())) ) | |
e304c27b BS |
1060 | { |
1061 | ostringstream msg; | |
1062 | msg << "Shutting down parent process ..." << endl; | |
cbbdeb6c | 1063 | log_notice(msg.str(),level); |
e304c27b BS |
1064 | } |
1065 | } | |
0541cd71 BS |
1066 | |
1067 | ||
1068 | /** | |
1069 | * DNS cache record timeout | |
1070 | * @param hostname Hostname | |
1071 | * @param lastupdated Lastupdated | |
1072 | * @param dns_cache_ttl DNS cache TTL | |
1073 | * @param current_time Current time | |
1074 | */ | |
8a00a649 | 1075 | void Logger::print_recheck_dns_entry(const string& hostname, const int lastupdated, const int dns_cache_ttl, const int current_time) const |
0541cd71 | 1076 | { |
cbbdeb6c BS |
1077 | int level = 1; |
1078 | if ( (level <= Loglevel) || ((level <= ExternalWarningLevel) && (!ExternalWarningLog.empty())) ) | |
0541cd71 BS |
1079 | { |
1080 | ostringstream msg; | |
d5a516ba | 1081 | 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; |
cbbdeb6c | 1082 | log_notice(msg.str(),level); |
0541cd71 BS |
1083 | } |
1084 | } | |
1085 | ||
1086 | ||
1087 | /** | |
1088 | * Found following cached DNS record | |
1089 | * @param hostname Hostname | |
1090 | * @param cached_dns_entry IP | |
1091 | */ | |
8a00a649 | 1092 | void Logger::print_cached_dns_entry(const string& hostname, const string& cached_dns_entry, const string& lastupdated_ip) const |
0541cd71 | 1093 | { |
cbbdeb6c BS |
1094 | int level = 1; |
1095 | if ( (level <= Loglevel) || ((level <= ExternalWarningLevel) && (!ExternalWarningLog.empty())) ) | |
0541cd71 BS |
1096 | { |
1097 | ostringstream msg; | |
1098 | msg << "Cached DNS record for host <" << hostname << "> : " << cached_dns_entry << " Last updated IP: " << lastupdated_ip << endl; | |
cbbdeb6c | 1099 | log_notice(msg.str(),level); |
0541cd71 BS |
1100 | } |
1101 | } | |
8a00a649 BS |
1102 | |
1103 | ||
1104 | /** | |
1105 | * Missing proxy option on command line. | |
1106 | */ | |
1107 | void Logger::print_missing_cmd_proxy_option() const | |
1108 | { | |
cbbdeb6c BS |
1109 | int level = 0; |
1110 | if ( (level <= Loglevel) || ((level <= ExternalWarningLevel) && (!ExternalWarningLog.empty())) ) | |
8a00a649 BS |
1111 | { |
1112 | ostringstream msg; | |
1113 | msg << "Missing option to initialize proxy. http_proxy and http_proxy_port must be specified." << endl; | |
cbbdeb6c | 1114 | log_error(msg.str(),level); |
8a00a649 BS |
1115 | } |
1116 | } | |
1117 | ||
1118 | ||
1119 | /** | |
1120 | * Multiple option in service config file. | |
1121 | * @param service_conf_file Service config file | |
1122 | * @param message Multiple option text | |
1123 | */ | |
1124 | void Logger::print_multiple_service_conf_option(const string& service_conf_file, const string& message) const | |
1125 | { | |
cbbdeb6c BS |
1126 | int level = 0; |
1127 | if ( (level <= Loglevel) || ((level <= ExternalWarningLevel) && (!ExternalWarningLog.empty())) ) | |
8a00a649 BS |
1128 | { |
1129 | ostringstream msg; | |
1130 | msg << "Multiple occurrences of the same option in service config file detected: " << service_conf_file << " " << message << endl; | |
cbbdeb6c | 1131 | log_error(msg.str(),level); |
8a00a649 BS |
1132 | } |
1133 | } | |
1134 | ||
1135 | ||
1136 | /** | |
1137 | * Multiple option in main config file. | |
1138 | * @param service_conf_file Service config file | |
1139 | * @param message Multiple option text | |
1140 | */ | |
1141 | void Logger::print_multiple_main_conf_option(const string& main_conf_file, const string& message) const | |
1142 | { | |
cbbdeb6c BS |
1143 | int level = 0; |
1144 | if ( (level <= Loglevel) || ((level <= ExternalWarningLevel) && (!ExternalWarningLog.empty())) ) | |
8a00a649 BS |
1145 | { |
1146 | ostringstream msg; | |
1147 | msg << "Multiple occurrences of the same option in main config file detected: " << main_conf_file << " " << message << endl; | |
cbbdeb6c | 1148 | log_error(msg.str(),level); |
8a00a649 BS |
1149 | } |
1150 | } | |
1151 | ||
1152 | ||
1153 | /** | |
1154 | * Missing proxy option in main config file. | |
2dd2db3e | 1155 | * @param main_conf_filename The concerning config file. |
8a00a649 BS |
1156 | */ |
1157 | void Logger::print_missing_conf_proxy_option(const string& main_conf_filename) const | |
1158 | { | |
cbbdeb6c BS |
1159 | int level = 0; |
1160 | if ( (level <= Loglevel) || ((level <= ExternalWarningLevel) && (!ExternalWarningLog.empty())) ) | |
8a00a649 BS |
1161 | { |
1162 | ostringstream msg; | |
1163 | msg << "Missing option to initialize proxy in main config file: " << main_conf_filename << " http_proxy and http_proxy_port must be specified." << endl; | |
cbbdeb6c | 1164 | log_error(msg.str(),level); |
8a00a649 BS |
1165 | } |
1166 | } | |
2dd2db3e BS |
1167 | |
1168 | ||
1169 | /** | |
1170 | * There is no domain part in the given hostname | |
1171 | * @param hostname The hostname with no domain part in it. | |
1172 | */ | |
d5a516ba | 1173 | void Logger::print_no_domain_part(const string& hostname) const |
2dd2db3e BS |
1174 | { |
1175 | int level = 0; | |
1176 | if ( (level <= Loglevel) || ((level <= ExternalWarningLevel) && (!ExternalWarningLog.empty())) ) | |
1177 | { | |
1178 | ostringstream msg; | |
1179 | msg << "There is no domain part in the given hostname: " << hostname << endl; | |
1180 | log_notice(msg.str(),level); | |
1181 | } | |
1182 | } | |
d5a516ba BS |
1183 | |
1184 | ||
1185 | /** | |
1186 | * An curl error occured. | |
1187 | * @param url The url requested by the curl operation | |
1188 | * @param curl_err_code The resulting curl error code | |
1189 | */ | |
1190 | void Logger::print_curl_error(const string& url, const int curl_err_code) const | |
1191 | { | |
1192 | string curl_err = ""; | |
1193 | ||
1194 | if ( curl_err_code == 3 ) | |
1195 | curl_err = "CURLE_URL_MALFORMAT"; | |
1196 | else if ( curl_err_code == 6 ) | |
1197 | curl_err = "CURLE_COULDNT_RESOLVE_HOST"; | |
1198 | else if ( curl_err_code == 7 ) | |
1199 | curl_err = "CURLE_COULDNT_CONNECT"; | |
1200 | else | |
1201 | curl_err = "UNKNOWN"; | |
1202 | ||
1203 | int level = 0; | |
1204 | if ( (level <= Loglevel) || ((level <= ExternalWarningLevel) && (!ExternalWarningLog.empty())) ) | |
1205 | { | |
1206 | ostringstream msg; | |
1207 | msg << "Curl error while requesting following url: " << url << " Curl error code: " << curl_err_code << " "<< curl_err << endl; | |
1208 | log_warning(msg.str(),level); | |
1209 | } | |
1210 | } | |
1211 | ||
1212 | ||
1213 | /** | |
1214 | * An curl error occured. | |
1215 | * @param url The url requested by the curl operation | |
1216 | * @param curl_err_code The resulting curl error code | |
1217 | * @param curl_err_buff The curl error buffer | |
1218 | */ | |
1219 | void Logger::print_curl_error(const string& url, const int curl_err_code, const char * curl_err_buff) const | |
1220 | { | |
1221 | string curl_err = ""; | |
1222 | ||
1223 | if ( curl_err_code == 3 ) | |
1224 | curl_err = "CURLE_URL_MALFORMAT"; | |
1225 | else if ( curl_err_code == 6 ) | |
1226 | curl_err = "CURLE_COULDNT_RESOLVE_HOST"; | |
1227 | else if ( curl_err_code == 7 ) | |
1228 | curl_err = "CURLE_COULDNT_CONNECT"; | |
1229 | else | |
1230 | curl_err = "UNKNOWN"; | |
1231 | ||
1232 | int level = 0; | |
1233 | if ( (level <= Loglevel) || ((level <= ExternalWarningLevel) && (!ExternalWarningLog.empty())) ) | |
1234 | { | |
1235 | ostringstream msg; | |
1236 | msg << "Curl error while requesting following url: " << url << " Curl error code: " << curl_err_code << " "<< curl_err << " " << curl_err_buff << endl; | |
1237 | log_warning(msg.str(),level); | |
1238 | } | |
1239 | } | |
1240 | ||
1241 | ||
1242 | /** | |
1243 | * Prints out the data received by curl operation | |
1244 | * @param CurlWritedataBuff | |
1245 | */ | |
1246 | void Logger::print_curl_data(const string& curl_writedata_buff) const | |
1247 | { | |
1248 | int level = 1; | |
1249 | if ( (level <= Loglevel) || ((level <= ExternalWarningLevel) && (!ExternalWarningLog.empty())) ) | |
1250 | { | |
1251 | ostringstream msg; | |
b6228761 | 1252 | msg << "Data received by curl: " << curl_writedata_buff << endl; |
d5a516ba BS |
1253 | log_notice(msg.str(),level); |
1254 | } | |
1255 | } | |
1256 | ||
1257 | ||
1258 | /** | |
a03fb896 BS |
1259 | * Not authorized to perform requested update operation |
1260 | * @param service The requested service. | |
d5a516ba BS |
1261 | * @param username Username |
1262 | * @param password Password | |
1263 | */ | |
a03fb896 | 1264 | void Logger::print_service_not_authorized(const string& service, const string& username, const string& password) const |
d5a516ba BS |
1265 | { |
1266 | int level = 0; | |
1267 | if ( (level <= Loglevel) || ((level <= ExternalWarningLevel) && (!ExternalWarningLog.empty())) ) | |
1268 | { | |
1269 | ostringstream msg; | |
a03fb896 | 1270 | msg << "Not authorized to perform update operation on service: " << service << " Please check username and password: " << username << ":" << password << endl; |
d5a516ba BS |
1271 | log_warning(msg.str(),level); |
1272 | } | |
1273 | } | |
1274 | ||
1275 | ||
1276 | /** | |
1277 | * Prints out the http status code | |
1278 | * @param url Url | |
1279 | * @param output HTTP status code | |
1280 | */ | |
1281 | void Logger::print_http_status_code(const std::string& url, const long http_code) const | |
1282 | { | |
1283 | int level = 1; | |
1284 | if ( (level <= Loglevel) || ((level <= ExternalWarningLevel) && (!ExternalWarningLog.empty())) ) | |
1285 | { | |
1286 | ostringstream msg; | |
1287 | msg << "Requested URL: " << url << " Received HTTP status code: " << http_code << endl; | |
1288 | log_notice(msg.str(),level); | |
1289 | } | |
1290 | } | |
b6228761 BS |
1291 | |
1292 | ||
1293 | /** | |
1294 | * Generic failure while trying to update service | |
1295 | * @param url The requested URL | |
1296 | * @param curl_data The received curl_data from the server | |
1297 | */ | |
1298 | void Logger::print_update_failure(const string& url, const string& curl_data) const | |
1299 | { | |
1300 | int level = 0; | |
1301 | if ( (level <= Loglevel) || ((level <= ExternalWarningLevel) && (!ExternalWarningLog.empty())) ) | |
1302 | { | |
1303 | ostringstream msg; | |
1304 | msg << "Problem while trying to updating service. Requested URL: " << url << " Error Code from Server: " << curl_data << endl; | |
1305 | log_warning(msg.str(),level); | |
1306 | } | |
1307 | } | |
1a00eac6 BS |
1308 | |
1309 | ||
1310 | /** | |
b17fd691 BS |
1311 | * Generic failure while trying to update service |
1312 | * @param url The requested URL | |
1313 | * @param http_status_code The received http status code | |
1314 | */ | |
1315 | void Logger::print_update_failure(const string& url, const long http_status_code) const | |
1316 | { | |
1317 | int level = 0; | |
1318 | if ( (level <= Loglevel) || ((level <= ExternalWarningLevel) && (!ExternalWarningLog.empty())) ) | |
1319 | { | |
1320 | ostringstream msg; | |
1321 | msg << "Problem while trying to updating service. Requested URL: " << url << " Error Code from Server: " << http_status_code << endl; | |
1322 | log_warning(msg.str(),level); | |
1323 | } | |
1324 | } | |
1325 | ||
1326 | /** | |
1a00eac6 BS |
1327 | * Hostname is invalid, contains no or only one domain part. |
1328 | * @param hostname The full qualified host name. | |
1329 | */ | |
4ef36a12 | 1330 | void Logger::print_invalid_hostname(const string& hostname) const |
1a00eac6 BS |
1331 | { |
1332 | int level = 0; | |
1333 | if ( (level <= Loglevel) || ((level <= ExternalWarningLevel) && (!ExternalWarningLog.empty())) ) | |
1334 | { | |
1335 | ostringstream msg; | |
1336 | msg << "The configured hostname: " << hostname << " is invalid. Please add the corresponding domain part." << endl; | |
1337 | log_warning(msg.str(),level); | |
1338 | } | |
1339 | } | |
4ef36a12 BS |
1340 | |
1341 | ||
1342 | /** | |
1343 | * An IP in a private range was detected | |
1344 | * @param ip The private IP | |
1345 | */ | |
1346 | void Logger::print_ip_is_local(const string& ip) const | |
1347 | { | |
1348 | int level = 0; | |
1349 | if ( (level <= Loglevel) || ((level <= ExternalWarningLevel) && (!ExternalWarningLog.empty())) ) | |
1350 | { | |
1351 | ostringstream msg; | |
1352 | msg << "The detected IP is within a private IP range: " << ip << endl; | |
1353 | log_warning(msg.str(),level); | |
1354 | } | |
1355 | } | |
1356 | ||
1357 | ||
1358 | /** | |
1359 | * Regex is matching in string | |
1360 | * @param regex The regex pattern | |
1361 | * @param matching_string The string | |
1362 | */ | |
a78b44b5 | 1363 | void Logger::print_regex_match(const string& regex, const string& matching_string) const |
4ef36a12 BS |
1364 | { |
1365 | int level = 1; | |
1366 | if ( (level <= Loglevel) || ((level <= ExternalWarningLevel) && (!ExternalWarningLog.empty())) ) | |
1367 | { | |
1368 | ostringstream msg; | |
1369 | msg << "Regex: " << regex << " is matching in: " << matching_string << endl; | |
1370 | log_notice(msg.str(),level); | |
1371 | } | |
1372 | } | |
a78b44b5 BS |
1373 | |
1374 | ||
1375 | /** | |
1376 | * Regex is not matching | |
1377 | * @param regex Regex | |
1378 | * @param not_matching_string String | |
1379 | */ | |
1380 | void Logger::print_no_regex_match(const string& regex, const string& not_matching_string) const | |
1381 | { | |
1382 | int level = 1; | |
1383 | if ( (level <= Loglevel) || ((level <= ExternalWarningLevel) && (!ExternalWarningLog.empty())) ) | |
1384 | { | |
1385 | ostringstream msg; | |
1386 | msg << "Regex: " << regex << " is not matching in: " << not_matching_string << endl; | |
1387 | log_warning(msg.str(),level); | |
1388 | } | |
1389 | } | |
1390 | ||
1391 | ||
1392 | /** | |
1393 | * Could not parse gnudip initial reply. | |
1394 | * @param curl_data The data received from gnudip server which should contain salt, time and sign. | |
1395 | */ | |
1396 | void Logger::print_could_not_parse_received_data(const string& curl_data) const | |
1397 | { | |
1398 | int level = 0; | |
1399 | if ( (level <= Loglevel) || ((level <= ExternalWarningLevel) && (!ExternalWarningLog.empty())) ) | |
1400 | { | |
1401 | ostringstream msg; | |
1402 | msg << "Could not parse salt, time and sign from initial gnudip server reply: " << curl_data << endl; | |
1403 | log_warning(msg.str(),level); | |
1404 | } | |
1405 | } | |
1406 | ||
1407 | ||
1408 | /** | |
1409 | * Gnudip salt, time and sign could not be got from map | |
1410 | */ | |
1411 | void Logger::print_could_not_get_initial_gnudip_data() const | |
1412 | { | |
1413 | int level = 0; | |
1414 | if ( (level <= Loglevel) || ((level <= ExternalWarningLevel) && (!ExternalWarningLog.empty())) ) | |
1415 | { | |
1416 | ostringstream msg; | |
1417 | msg << "Could not get salt, time and sign from map." << endl; | |
1418 | log_warning(msg.str(),level); | |
1419 | } | |
1420 | } | |
1421 | ||
1422 | ||
a2f5be94 BS |
1423 | |
1424 | /** | |
1425 | * Gnudip protocol requires explicit declaration of a servername. | |
1426 | */ | |
a78b44b5 BS |
1427 | void Logger::print_gnudip_requires_servername() const |
1428 | { | |
1429 | int level = 0; | |
1430 | if ( (level <= Loglevel) || ((level <= ExternalWarningLevel) && (!ExternalWarningLog.empty())) ) | |
1431 | { | |
1432 | ostringstream msg; | |
1433 | msg << "Gnudip requires explicit definition of servername via config!" << endl; | |
1434 | log_warning(msg.str(),level); | |
1435 | } | |
1436 | } | |
a2f5be94 BS |
1437 | |
1438 | ||
1439 | /** | |
1440 | * An exception occured while computing the md5 sum. | |
1441 | * @param what The exception occured. | |
1442 | */ | |
1443 | void Logger::print_exception_md5_sum(const std::string& what) const | |
1444 | { | |
1445 | int level = 0; | |
1446 | if ( (level <= Loglevel) || ((level <= ExternalWarningLevel) && (!ExternalWarningLog.empty())) ) | |
1447 | { | |
1448 | ostringstream msg; | |
1449 | msg << "An exception occured while computing a md5 sum: " << what << endl; | |
1450 | log_error(msg.str(),level); | |
1451 | } | |
1452 | } | |
a03fb896 BS |
1453 | |
1454 | ||
1455 | /** | |
1456 | * An network exception occured. | |
1457 | * @param what The exception occured. | |
1458 | */ | |
1459 | void Logger::print_network_error(const std::string& what) const | |
1460 | { | |
1461 | int level = 0; | |
1462 | if ( (level <= Loglevel) || ((level <= ExternalWarningLevel) && (!ExternalWarningLog.empty())) ) | |
1463 | { | |
1464 | ostringstream msg; | |
1465 | msg << "An netowrk exception occured: " << what << endl; | |
1466 | log_error(msg.str(),level); | |
1467 | } | |
1468 | } | |
1469 | ||
1470 | ||
1471 | /** | |
1472 | * An undefined protocol error occured. | |
1473 | * @param protocol The protocol | |
1474 | * @param error The error | |
1475 | */ | |
1476 | void Logger::print_undefined_protocol_error(const std::string& protocol, const std::string& error) const | |
1477 | { | |
1478 | int level = 0; | |
1479 | if ( (level <= Loglevel) || ((level <= ExternalWarningLevel) && (!ExternalWarningLog.empty())) ) | |
1480 | { | |
1481 | ostringstream msg; | |
1482 | msg << "An undefined protocol error occured. Protocol: " << protocol << " Error: " << error << endl; | |
1483 | log_error(msg.str(),level); | |
1484 | } | |
1485 | } |