Improve logging when IP update is not allowed (log once on log level 0 if we changed...
[bpdyndnsd] / src / logger.hpp
CommitLineData
254bbf53
BS
1/** @file
2 * @brief Logger class header. This class represents the Logging facility.
3 *
4 *
5 *
6 * @copyright Intra2net AG
7 * @license GPLv2
8*/
9
10#ifndef LOGGER_H
11#define LOGGER_H
12
88a594e8 13#include <string>
2dd2db3e 14#include <list>
7f3ced8c 15
88a594e8
BS
16#include <boost/program_options.hpp>
17#include <boost/shared_ptr.hpp>
27baf279 18
31af6a2e
BS
19#include <curl/curl.h>
20
254bbf53
BS
21class Logger
22{
88a594e8 23
8bca3c5d 24private:
88a594e8 25
8bca3c5d
BS
26 int Loglevel;
27 bool Syslog;
cbbdeb6c
BS
28 std::string ExternalWarningLog;
29 int ExternalWarningLevel;
e8787e2e
BS
30 std::set<std::string> ExternalSendMessages;
31 bool ExternalLogOnlyOnce;
254bbf53
BS
32
33public:
34
88a594e8
BS
35 typedef boost::shared_ptr<Logger> Ptr;
36
254bbf53
BS
37 Logger();
38
39 ~Logger();
40
e8787e2e
BS
41 void set_external_log_only_once( const bool _external_log_only_once );
42
43 void clear_external_send_messages();
44
47e0ee60
BS
45 std::string escape_shellarg(const std::string &input);
46
ce70569b 47 void log_notice(const std::string& msg) const;
59c8d63c 48
e8787e2e 49 void log_warning(const std::string& msg, int loglevel);
59c8d63c 50
ce70569b 51 void log_error(const std::string& msg) const;
59c8d63c 52
e8d4a6f8 53 void set_loglevel(const int _loglevel);
8bca3c5d 54
b38684ce 55 int get_loglevel() const;
8bca3c5d 56
e8d4a6f8 57 void set_syslog(const bool _syslog);
8bca3c5d 58
b38684ce 59 bool get_syslog() const;
8bca3c5d 60
e8787e2e 61 void set_log_facility(const int _loglevel, const bool _syslog, const std::string& _external_error_log, const int _external_error_level, const bool _external_log_only_once );
8bca3c5d 62
4475e30a
BS
63 bool is_allowed_to_send( const std::string& msg ) const;
64
65 // Start log messages.
66
92beaba3 67 void print_usage(const boost::shared_ptr<boost::program_options::options_description> opt_desc) const;
254bbf53 68
b38684ce 69 void print_version() const;
254bbf53 70
e38d7604
TJ
71 void print_started() const;
72
b38684ce 73 void print_cmd_parsed() const;
254bbf53 74
b38684ce 75 void print_conf_files_parsed() const;
667c672c 76
e8d4a6f8 77 void print_destructor_call(const std::string& _class) const;
254bbf53 78
e8d4a6f8 79 void print_constructor_call(const std::string& _class) const;
254bbf53 80
e8d4a6f8 81 void print_update_service(const std::string& service) const;
254bbf53 82
0f0908e1
TJ
83 void print_update_service_is_blocked(const std::string& service, int remaining_seconds) const;
84
85 void print_block_service(const std::string& service, int block_seconds) const;
86
e8d4a6f8 87 void print_unknown_cmd_option(const std::string& unknown_option) const;
254bbf53 88
e8d4a6f8 89 void print_unknown_protocol(const std::string& protocol) const;
254bbf53 90
e8d4a6f8 91 void print_load_service_conf(const std::string& filename) const;
254bbf53 92
e8d4a6f8 93 void print_load_main_conf(const std::string& filename) const;
254bbf53 94
8a00a649 95 void print_unknown_service_conf_option(const std::string& service_conf_file, const std::string& unknown_option) const;
254bbf53 96
e8d4a6f8 97 void print_unknown_main_conf_option(const std::string& unknown_option) const;
254bbf53 98
e8d4a6f8 99 void print_error_opening_r(const std::string& filename) const;
667c672c 100
e8d4a6f8 101 void print_error_opening_rw(const std::string& filename) const;
254bbf53 102
e8d4a6f8 103 void print_error_config_path(const std::string& config_path) const;
254bbf53 104
e8d4a6f8 105 void print_conf_loaded(const std::string& config_path) const;
254bbf53 106
e8d4a6f8 107 void print_conf_not_loaded(const std::string& config_path) const;
254bbf53 108
5b3f3f54
TJ
109 void print_conf_reload_failed_exit() const;
110
b38684ce 111 void print_missing_cmd_service_option() const;
388f4ab0 112
8a00a649
BS
113 void print_missing_service_conf_option(const std::string& service_conf_file) const;
114
e8d4a6f8 115 void print_runnig_as_daemon(const int pid) const;
388f4ab0 116
e8d4a6f8 117 void print_daemon_mode(const bool daemon_mode) const;
388f4ab0 118
b38684ce 119 void print_error_fork() const;
388f4ab0 120
e8d4a6f8 121 void print_pid_found(const int pid) const;
388f4ab0 122
e8d4a6f8 123 void print_process_already_running(const int pid) const;
c5675c01 124
b38684ce 125 void print_caught_sigterm() const;
c5675c01 126
b38684ce 127 void print_caught_siguser1() const;
c5675c01 128
b38684ce 129 void print_caught_sighup() const;
8bca3c5d 130
64ff14c3
BS
131 void print_caught_siguser2() const;
132
133 void print_caught_sigrtmin() const;
134
3f39b968
TJ
135 void print_caught_sigrtmax(int new_loglevel) const;
136
e8d4a6f8 137 void print_error_setting_signal(const std::string& signal) const;
8bca3c5d 138
b38684ce 139 void print_init_log_facility() const;
8bca3c5d 140
b38684ce 141 void print_offline_mode() const;
27baf279 142
c7a2055a
TJ
143 void print_sleep_dialup_mode(time_t sleep_until) const;
144
b38684ce 145 void print_serialized_objects_success() const;
27baf279 146
b38684ce 147 void print_deserialized_objects_success() const;
27baf279 148
62df5f33 149 void print_service_object(const std::string& message, const std::string& protocol, const std::string& hostname, const std::string& login, const std::string& password, const int update_interval, const int max_updates_within_interval, const int dns_cache_ttl , const std::string& actual_ip, std::list<time_t> lastupdated) const;
5d38cfe6 150
ce70569b 151 void print_exception_serialize(const std::string& errMsg) const;
667c672c 152
ce70569b 153 void print_exception_deserialize(const std::string& errMsg) const;
667c672c 154
e8d4a6f8 155 void print_error_kill_child(const int pid) const;
667c672c 156
e8d4a6f8 157 void print_child_killed(const int pid) const;
584b9407 158
e8787e2e 159 void print_no_object_file(const std::string& object_file);
0665b239 160
e8d4a6f8 161 void print_hostname(const std::string& hostname) const;
0665b239 162
c3dea5dc 163 void print_own_ipv4(const std::string& ip_addr_v4, const std::string& hostname) const;
019dc0d9 164
c3dea5dc 165 void print_own_ipv6(const std::string& ip_addr_v6, const std::string& hostname) const;
0665b239 166
ce70569b 167 void print_error_hostname_to_ip(const std::string& errMsg, const std::string& hostname) const;
68c6b4af 168
e8d4a6f8 169 void print_update_service_successful(const std::string& service) const;
1c0908b5 170
e8787e2e 171 void print_webcheck_no_ip();
1c0908b5 172
f3141675
TJ
173 void print_no_wan_ip(bool override_log_level) const;
174
62956d9a
TJ
175 void print_external_wan_ip(bool override_log_level, const std::string &wan_ip) const;
176
f3141675 177 void print_dns_lookup_failed(bool override_log_level, const std::string &hostname) const;
1d2e2f56 178
e8787e2e 179 void print_webcheck_url_connection_problem(const char * curl_err_buff, const std::string& url);
1c0908b5 180
e8d4a6f8 181 void print_webcheck_error(const char * curl_err_buff, const std::string& url) const;
1c0908b5 182
e8d4a6f8 183 void print_received_curl_data(const std::string& curl_data) const;
1c0908b5 184
e8d4a6f8 185 void print_regex_found_ip(const std::string& ip) const;
1c0908b5 186
e8787e2e 187 void print_regex_ip_not_found(const std::string& data);
3c0cd271 188
e8d4a6f8 189 void print_multiple_cmd_option(const std::string& message) const;
3c0cd271 190
8a00a649
BS
191 void print_multiple_service_conf_option(const std::string& service_conf_file, const std::string& message) const;
192
193 void print_multiple_main_conf_option(const std::string& main_conf_file, const std::string& message) const;
194
0ebcd4ef 195 void print_update_not_allowed(bool override_log_level, const time_t current_time, const time_t old_time, const int MaxUpdatesWithinInterval, const std::string& service);
3c0cd271 196
e8787e2e 197 void print_update_service_failure(const std::string& service);
e304c27b
BS
198
199 void print_starting_shutdown() const;
200
201 void print_shutdown_succeeded() const;
202
203 void print_shutdown_parent_succeeded() const;
204
205 void print_starting_shutdown_parent() const;
0541cd71
BS
206
207 void print_recheck_dns_entry(const std::string& hostname, const int lastupdated, const int dns_cache_ttl, const int current_time) const;
208
8a00a649
BS
209 void print_missing_cmd_proxy_option() const;
210
211 void print_missing_conf_proxy_option(const std::string& main_conf_filename) const;
2dd2db3e
BS
212
213 void print_no_domain_part(const std::string& hostname) const;
d5a516ba 214
c730deea 215 void print_curl_error_init(const std::string& err_msg, const CURLcode curl_err_code) const;
31af6a2e
BS
216
217 void print_curl_error(const std::string& url, const CURLcode curl_err_code) const;
d5a516ba 218
c730deea 219 void print_curl_error(const std::string& url, const CURLcode curl_err_code, const char * curl_err_buff) const;
d5a516ba
BS
220
221 void print_curl_data(const std::string& curl_writedata_buff) const;
222
a03fb896 223 void print_service_not_authorized(const std::string& service, const std::string& username, const std::string& password) const;
d5a516ba 224
e8787e2e 225 void print_httphelper_not_initialized() const;
31af6a2e 226
d5a516ba 227 void print_http_status_code(const std::string& url, const long http_code) const;
b6228761
BS
228
229 void print_update_failure(const std::string& url, const std::string& curl_data) const;
1a00eac6 230
b17fd691
BS
231 void print_update_failure(const std::string& url, const long http_status_code) const;
232
e8787e2e 233 void print_invalid_hostname(const std::string& hostname);
4ef36a12 234
e8787e2e 235 void print_ip_is_local(const std::string& ip);
4ef36a12
BS
236
237 void print_regex_match(const std::string& regex, const std::string& matching_string) const;
a78b44b5 238
e8787e2e 239 void print_no_regex_match(const std::string& regex, const std::string& not_matching_string);
a78b44b5
BS
240
241 void print_could_not_parse_received_data(const std::string& curl_data) const;
242
243 void print_could_not_get_initial_gnudip_data() const;
244
e8787e2e 245 void print_gnudip_requires_servername();
a2f5be94
BS
246
247 void print_exception_md5_sum(const std::string& what) const;
a03fb896
BS
248
249 void print_network_error(const std::string& what) const;
250
251 void print_undefined_protocol_error(const std::string& protocol, const std::string& error) const;
d77313ea
BS
252
253 void print_error_external_logging(const std::string& external_prog) const;
c1b8cb79
BS
254
255 void print_error_parsing_config_file(const std::string& filename, const std::string& error) const;
256
257 void print_error_parsing_cmd(const std::string& error) const;
2b0f7c11 258
c730deea 259 void print_webcheck_exceed_interval( const time_t last_webcheck, const int webcheck_interval, const time_t current_time ) const;
1af7c124 260
c730deea 261 void print_check_service_update(const std::string& hostname, const time_t current_time, const time_t lastupdated) const;
1af7c124
BS
262
263 void print_cached_dns_entry(const std::string& hostname, const std::string& ip_dns_recheck, const std::string& ip_last_update, const std::string& ip_host) const;
264
08a5a621 265 void print_update_service(const std::string& hostname, const std::string& ip_dns_recheck, const std::string& ip_last_update, const std::string& ip_host, const time_t lastupdated) const;
1af7c124 266
08a5a621 267 void print_update_service_ttl_expired(const std::string& hostname, const std::string& ip_dns_recheck, const std::string& ip_last_update, const std::string& ip_host, const time_t lastupdated, const int dns_cache_ttl, const time_t current_time) const;
1af7c124 268
d55e13a6 269 void print_update_service_ttl_not_expired(bool override_log_level, const std::string& hostname, const std::string& ip_dns_recheck, const std::string& ip_last_update, const std::string& ip_host, const time_t lastupdated, const int dns_cache_ttl, const time_t current_time) const;
1af7c124 270
d55e13a6 271 void print_no_update_needed(bool override_log_level, const std::string& hostname, const std::string& ip_dns_recheck, const std::string& ip_last_update, const std::string& ip_host, const time_t lastupdated) const;
1d2e2f56
BS
272
273 void print_error_getting_local_wan_ip(const std::string& system_call, const std::string& error) const;
60657d55
BS
274
275 void print_invalid_service_config() const;
e8787e2e 276
4475e30a 277 void print_msg( const std::string& msg ) const;
254bbf53
BS
278};
279
280#endif