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