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