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 BS |
28 | , ExternalWarningLog("") |
29 | , ExternalWarningLevel(0) | |
254bbf53 | 30 | { |
cbbdeb6c | 31 | set_log_facility(Loglevel,Syslog,ExternalWarningLog,ExternalWarningLevel); |
254bbf53 BS |
32 | } |
33 | ||
34 | ||
35 | /** | |
36 | * Default Destructor | |
37 | */ | |
38 | Logger::~Logger() | |
39 | { | |
254bbf53 BS |
40 | } |
41 | ||
42 | ||
43 | /** | |
59c8d63c BS |
44 | * Decides if Logging through syslog if enabled or through std. |
45 | * @param msg The message to log. | |
46 | */ | |
cbbdeb6c | 47 | void Logger::log_notice(const string& msg, int level) const |
59c8d63c BS |
48 | { |
49 | if ( Syslog ) | |
50 | syslog(LOG_NOTICE,msg.c_str()); | |
51 | else | |
27baf279 | 52 | cout << msg << endl;; |
59c8d63c BS |
53 | } |
54 | ||
55 | ||
56 | /** | |
57 | * Decides if Logging through syslog if enabled or through std. | |
58 | * @param msg The message to log. | |
59 | */ | |
cbbdeb6c | 60 | void Logger::log_warning(const string& msg, int level) const |
59c8d63c BS |
61 | { |
62 | if ( Syslog ) | |
63 | syslog(LOG_WARNING,msg.c_str()); | |
64 | else | |
27baf279 | 65 | cout << msg << endl; |
cbbdeb6c BS |
66 | |
67 | if ( (level <= ExternalWarningLevel) && (!ExternalWarningLog.empty()) ) | |
68 | { | |
69 | string external = ExternalWarningLog; | |
70 | external.append(" "); | |
efbde536 | 71 | external.append("\""); |
cbbdeb6c | 72 | external.append(msg); |
efbde536 | 73 | external.append("\""); |
cbbdeb6c BS |
74 | int ret_val = system(external.c_str()); |
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 | */ | |
3c0cd271 | 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 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; | |
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; | |
1080 | msg << "DNS cache record for host <" << hostname << "> expired: Lastupdated: " << lastupdated << " DNS cache ttl: " << dns_cache_ttl << " Current time: " << current_time << " Checking current DNS cache status." << endl; | |
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 | */ | |
1172 | void Logger::print_no_domain_part(const std::string& hostname) const | |
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 | } |