Implemented daemon ability.
[bpdyndnsd] / src / logger.cpp
CommitLineData
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 */
17Logger::Logger()
18{
19 print_constructor_call("Logger");
20}
21
22
23/**
24 * Default Destructor
25 */
26Logger::~Logger()
27{
28 print_destructor_call("Logger");
29}
30
31
32/**
33 * Prints out the usage to the command line.
34 */
35void 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 */
46void 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 */
57void 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 */
67void 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 */
77void 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 */
87void 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 */
97void 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 */
107void 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 */
117void 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
127void 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
137void 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
147void 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
157void 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
167void 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
177void 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
187void 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
196void 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
202void Logger::print_runnig_as_daemon(const int pid)
203{
204 cout << "Runnig as daemon: " << pid << endl;
205}
206
207void Logger::print_daemon_mode(const bool daemon_mode)
208{
209 string mode = "disabled";
210 if (daemon_mode == true)
211 mode = "enabled";
212 cout << "Daemon mode is " << mode << "." << endl;
213}
214
215
216void Logger::print_error_fork()
217{
218 cerr << "Error while trying to fork." << endl;
219}
220
221
222void Logger::print_pid_found(const int pid)
223{
224 cout << "Pidfile found: " << pid << ". Checking if process is still runnig..." << endl;
225}
226
227
228void Logger::print_process_already_running(const int pid)
229{
230 cerr << "Another bpdyndnsd process with PID " << pid << " is already running!" << endl;
231}