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 | ||
13 | ||
14 | /** | |
15 | * Default Constructor | |
16 | */ | |
17 | Logger::Logger() | |
18 | { | |
19 | print_constructor_call("Logger"); | |
20 | } | |
21 | ||
22 | ||
23 | /** | |
24 | * Default Destructor | |
25 | */ | |
26 | Logger::~Logger() | |
27 | { | |
28 | print_destructor_call("Logger"); | |
29 | } | |
30 | ||
31 | ||
32 | /** | |
33 | * Prints out the usage to the command line. | |
34 | */ | |
35 | void Logger::print_usage(const po::options_description* opt_desc) | |
36 | { | |
37 | cout << "Usage: bpdyndnsd [Command line options]" << "\n" << endl; | |
38 | cout << *opt_desc << endl; | |
39 | } | |
40 | ||
41 | ||
42 | /** | |
43 | * Prints out the programm name and the given version string on stdout. | |
44 | * @param version Version string. | |
45 | */ | |
46 | void Logger::print_version() | |
47 | { | |
48 | ostringstream version_string; | |
49 | version_string << VERSION << "." << REVISION << "." << RELEASE; | |
50 | cout << "Bullet proof dynamic dns daemon.\nbpdyndnsd " << version_string.str() << endl; | |
51 | } | |
52 | ||
53 | ||
54 | /** | |
55 | * Prints out the successful parsing of the command line options. | |
56 | */ | |
57 | void Logger::print_cmd_parsed() | |
58 | { | |
59 | cout << "Command line options successfully parsed." << endl; | |
60 | } | |
61 | ||
62 | ||
63 | /** | |
64 | * Prints out the successful parsing of the config files. | |
daf2ea82 | 65 | * @param config_path The specified config path. |
254bbf53 BS |
66 | */ |
67 | void Logger::print_conf_loaded(const string& config_path) | |
68 | { | |
69 | cout << "Config files successfully loaded in: " << config_path << endl; | |
70 | } | |
71 | ||
72 | ||
73 | /** | |
daf2ea82 BS |
74 | * Prints out the unsuccessful parsing of the config files. |
75 | * @param config_path The specified config path. | |
254bbf53 BS |
76 | */ |
77 | void Logger::print_conf_not_loaded(const string& config_path) | |
78 | { | |
daf2ea82 | 79 | cerr << "Config files couldn't be loaded in: " << config_path << endl; |
254bbf53 BS |
80 | } |
81 | ||
82 | ||
83 | /** | |
daf2ea82 BS |
84 | * A file could not be opened for reading. |
85 | * @param filename The filename. | |
254bbf53 BS |
86 | */ |
87 | void Logger::print_error_opening(const string& filename) | |
88 | { | |
daf2ea82 | 89 | cerr << "Error opening file for reading: " << filename << endl; |
254bbf53 BS |
90 | } |
91 | ||
92 | ||
93 | /** | |
94 | * Desctructor of specified class was called. | |
95 | * @param _class Name of the class. | |
96 | */ | |
97 | void Logger::print_destructor_call(const string& _class) | |
98 | { | |
99 | cout << "Destructor call: " << _class << endl; | |
100 | } | |
101 | ||
102 | ||
103 | /** | |
104 | * Constructor of specified class was called. | |
105 | * @param _class Name of the class. | |
106 | */ | |
107 | void Logger::print_constructor_call(const string& _class) | |
108 | { | |
109 | cout << "Constructor call: " << _class << endl; | |
110 | } | |
111 | ||
112 | ||
113 | /** | |
114 | * Update method for specified service was called. | |
daf2ea82 | 115 | * @param service The service for which is the update running. |
254bbf53 BS |
116 | */ |
117 | void Logger::print_update_service(const string& service) | |
118 | { | |
119 | cout << "Running update for service: " << service << endl; | |
120 | } | |
121 | ||
122 | ||
daf2ea82 BS |
123 | /** |
124 | * An unknown option on the command line was detected. | |
125 | * @param unknown_option The unknown option. | |
126 | */ | |
254bbf53 BS |
127 | void Logger::print_unknown_cmd_option(const string& unknown_option) |
128 | { | |
daf2ea82 | 129 | cerr << "Unknown option on command line detected: " << unknown_option << endl; |
254bbf53 BS |
130 | } |
131 | ||
132 | ||
daf2ea82 BS |
133 | /** |
134 | * An unknown protocol was specified. | |
135 | * @param protocol The unknown protocol. | |
136 | */ | |
254bbf53 BS |
137 | void Logger::print_unknown_protocol(const string& protocol) |
138 | { | |
daf2ea82 | 139 | cerr << "Unknown protocol defined: " << protocol << endl; |
254bbf53 BS |
140 | } |
141 | ||
142 | ||
daf2ea82 BS |
143 | /** |
144 | * Loading a service config file. | |
145 | * @param filename The service config file. | |
146 | */ | |
254bbf53 BS |
147 | void Logger::print_load_service_conf(const string& filename) |
148 | { | |
149 | cout << "Loading service config file: " << filename << endl; | |
150 | } | |
151 | ||
152 | ||
daf2ea82 BS |
153 | /** |
154 | * Loading the main config file. | |
155 | * @param filename The main config file. | |
156 | */ | |
254bbf53 BS |
157 | void Logger::print_load_main_conf(const string& filename) |
158 | { | |
159 | cout << "Loading main config file: " << filename << endl; | |
160 | } | |
161 | ||
162 | ||
daf2ea82 BS |
163 | /** |
164 | * There is an unknown option in a service config file. | |
165 | * @param unknown_option The unknown option. | |
166 | */ | |
254bbf53 BS |
167 | void Logger::print_unknown_service_conf_option(const string& unknown_option) |
168 | { | |
daf2ea82 | 169 | cerr << "Unknown option in service config file detected: " << unknown_option << endl; |
254bbf53 BS |
170 | } |
171 | ||
172 | ||
daf2ea82 BS |
173 | /** |
174 | * There is an unknown option in the main config file. | |
175 | * @param unknown_option The unknown option. | |
176 | */ | |
254bbf53 BS |
177 | void Logger::print_unknown_main_conf_option(const string& unknown_option) |
178 | { | |
daf2ea82 | 179 | cerr << "Unknown option in main config file detected: " << unknown_option << endl; |
254bbf53 BS |
180 | } |
181 | ||
182 | ||
daf2ea82 BS |
183 | /** |
184 | * The defined config path doesn't exist or is not a directory. | |
185 | * @param config_path The defined config path. | |
186 | */ | |
254bbf53 BS |
187 | void Logger::print_error_config_path(const string& config_path) |
188 | { | |
daf2ea82 | 189 | cerr << "Config path doesn't exists or is not a diretory: " << config_path << endl; |
254bbf53 BS |
190 | } |
191 | ||
192 | ||
daf2ea82 BS |
193 | /** |
194 | * There is a missing command line option to initialize a service object. | |
195 | */ | |
254bbf53 BS |
196 | void Logger::print_missing_cmd_service_option() |
197 | { | |
daf2ea82 | 198 | cerr << "Missing option to initialize service. Protocol, host, login and password must be specified." << endl; |
254bbf53 | 199 | } |
388f4ab0 BS |
200 | |
201 | ||
c5675c01 BS |
202 | /** |
203 | * Process running as daemon. | |
204 | * @param pid The pid of the daemon. | |
205 | */ | |
388f4ab0 BS |
206 | void Logger::print_runnig_as_daemon(const int pid) |
207 | { | |
208 | cout << "Runnig as daemon: " << pid << endl; | |
209 | } | |
210 | ||
c5675c01 BS |
211 | |
212 | /** | |
213 | * Prints out the daemon mode. | |
214 | * @param daemon_mode The daemon mode. | |
215 | */ | |
388f4ab0 BS |
216 | void Logger::print_daemon_mode(const bool daemon_mode) |
217 | { | |
218 | string mode = "disabled"; | |
219 | if (daemon_mode == true) | |
220 | mode = "enabled"; | |
221 | cout << "Daemon mode is " << mode << "." << endl; | |
222 | } | |
223 | ||
224 | ||
c5675c01 BS |
225 | /** |
226 | * There was an error while trying to fork. | |
227 | */ | |
388f4ab0 BS |
228 | void Logger::print_error_fork() |
229 | { | |
230 | cerr << "Error while trying to fork." << endl; | |
231 | } | |
232 | ||
233 | ||
c5675c01 BS |
234 | /** |
235 | * A pid in the pidfile was found. | |
236 | * @param pid The pid found in the pidfile. | |
237 | */ | |
388f4ab0 BS |
238 | void Logger::print_pid_found(const int pid) |
239 | { | |
240 | cout << "Pidfile found: " << pid << ". Checking if process is still runnig..." << endl; | |
241 | } | |
242 | ||
243 | ||
c5675c01 BS |
244 | /** |
245 | * Another process is already running. | |
246 | * @param pid The pid of the other process. | |
247 | */ | |
388f4ab0 BS |
248 | void Logger::print_process_already_running(const int pid) |
249 | { | |
250 | cerr << "Another bpdyndnsd process with PID " << pid << " is already running!" << endl; | |
251 | } | |
c5675c01 BS |
252 | |
253 | ||
254 | /** | |
255 | * SIGTERM caught. | |
256 | */ | |
257 | void Logger::print_caught_sigterm() | |
258 | { | |
259 | cout << "Caught SIGTERM. Exiting..." << endl; | |
260 | } | |
261 | ||
262 | ||
263 | /** | |
264 | * SIGUSR1 caught. | |
265 | */ | |
266 | void Logger::print_caught_siguser1() | |
267 | { | |
268 | cout << "Caught SIGUSR1. Switching to offline mode..." << endl; | |
269 | } | |
270 | ||
271 | ||
272 | /** | |
273 | * SIGHUP caught. | |
274 | */ | |
275 | void Logger::print_caught_sighup() | |
276 | { | |
277 | cout << "Caught SIGHUP. Reloading config and switching to online mode..." << endl; | |
278 | } |