Skip to content

Commit 0de0bf7

Browse files
committed
Make debug logs active with _DEBUG.
1 parent eae5b19 commit 0de0bf7

File tree

4 files changed

+35
-15
lines changed

4 files changed

+35
-15
lines changed

webserver/cWebem.cpp

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -952,7 +952,9 @@ int cWebem::CountSessions() {
952952
}
953953

954954
void cWebem::CleanSessions() {
955-
//_log.Log(LOG_STATUS, "[web:%s] cleaning sessions...", GetPort().c_str());
955+
#ifdef _DEBUG
956+
_log.Log(LOG_STATUS, "[web:%s] cleaning sessions...", GetPort().c_str());
957+
#endif
956958
int before = CountSessions();
957959
// Clean up timed out sessions from memory
958960
std::vector<std::string> ssids;
@@ -1631,7 +1633,9 @@ void cWebemRequestHandler::handle_request(const request& req, reply& rep)
16311633
// Find and include any special cWebem strings
16321634
if (!myWebem->Include(rep.content)) {
16331635
if (mInfo.mtime_support && !mInfo.is_modified) {
1634-
//_log.Log(LOG_STATUS, "[web:%s] %s not modified (1).", myWebem->GetPort().c_str(), req.uri.c_str());
1636+
#ifdef _DEBUG
1637+
_log.Log(LOG_STATUS, "[web:%s] %s not modified (1).", myWebem->GetPort().c_str(), req.uri.c_str());
1638+
#endif
16351639
rep = reply::stock_reply(reply::not_modified);
16361640
return;
16371641
}
@@ -1654,7 +1658,9 @@ void cWebemRequestHandler::handle_request(const request& req, reply& rep)
16541658
{
16551659
if (mInfo.mtime_support && !mInfo.is_modified) {
16561660
rep = reply::stock_reply(reply::not_modified);
1657-
//_log.Log(LOG_STATUS, "[web:%s] %s not modified (2).", myWebem->GetPort().c_str(), req.uri.c_str());
1661+
#ifdef _DEBUG
1662+
_log.Log(LOG_STATUS, "[web:%s] %s not modified (2).", myWebem->GetPort().c_str(), req.uri.c_str());
1663+
#endif
16581664
return;
16591665
}
16601666
//Cache images
@@ -1664,7 +1670,9 @@ void cWebemRequestHandler::handle_request(const request& req, reply& rep)
16641670
else {
16651671
if (mInfo.mtime_support && !mInfo.is_modified) {
16661672
rep = reply::stock_reply(reply::not_modified);
1667-
//_log.Log(LOG_STATUS, "[web:%s] %s not modified (3).", myWebem->GetPort().c_str(), req.uri.c_str());
1673+
#ifdef _DEBUG
1674+
_log.Log(LOG_STATUS, "[web:%s] %s not modified (3).", myWebem->GetPort().c_str(), req.uri.c_str());
1675+
#endif
16681676
return;
16691677
}
16701678
}

webserver/connection.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,9 @@ void connection::reset_read_timeout() {
320320
/// stop connection on read timeout
321321
void connection::handle_read_timeout(const boost::system::error_code& error) {
322322
if (error != boost::asio::error::operation_aborted) {
323-
//_log.Log(LOG_STATUS, "%s -> handle read timeout", host_endpoint_.c_str());
323+
#ifdef _DEBUG
324+
_log.Log(LOG_STATUS, "%s -> handle read timeout", host_endpoint_.c_str());
325+
#endif
324326
connection_manager_.stop(shared_from_this());
325327
}
326328
}

webserver/connection_manager.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,10 @@ void connection_manager::stop(connection_ptr c)
5555

5656
void connection_manager::stop_all(bool graceful_stop)
5757
{
58-
//_log.Log(LOG_STATUS,"connection_manager::stop_all(%s)", graceful_stop ? "true" : "false");
58+
#ifdef _DEBUG
59+
_log.Log(LOG_STATUS,"%stopping connections...", graceful_stop ? "Gracefully s" : "S");
60+
#endif
5961
if (graceful_stop) {
60-
_log.Log(LOG_STATUS,"Gracefully stopping connections...");
6162
std::for_each(connections_.begin(), connections_.end(),
6263
boost::bind(&connection::stop_gracefully, _1));
6364
int timeout = 10; // force stop after 10 seconds
@@ -68,17 +69,20 @@ void connection_manager::stop_all(bool graceful_stop)
6869
}
6970
if ((mytime(NULL) - start) > timeout) {
7071
// timeout occurred : force stop
72+
#ifdef _DEBUG
7173
_log.Log(LOG_STATUS,"Graceful stop timeout occurred : remaining connections will be closed now");
74+
#endif
7275
break;
7376
}
74-
//_log.Log(LOG_STATUS,"Graceful stopping : %d active connection(s)", (int) connections_.size());
77+
#ifdef _DEBUG
78+
_log.Log(LOG_STATUS,"Graceful stopping : %d active connection(s)", (int) connections_.size());
79+
#endif
7580
sleep_milliseconds(500);
7681
}
7782
}
7883
std::for_each(connections_.begin(), connections_.end(),
7984
boost::bind(&connection::stop, _1));
8085
connections_.clear();
81-
//_log.Log(LOG_STATUS,"connection_manager::stop_all(%s) ends", graceful_stop ? "true" : "false");
8286
}
8387

8488

webserver/server.cpp

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ server_base::server_base(const server_settings & settings, request_handler & use
2020
timeout_(20), // default read timeout in seconds
2121
is_running(false),
2222
is_stopping(false) {
23-
//_log.Log(LOG_STATUS, "[web:%s] create server_base using settings : %s", settings.listening_port.c_str(), settings.to_string().c_str());
2423
if (!settings.is_enabled()) {
2524
throw std::invalid_argument("cannot initialize a disabled server (listening port cannot be empty or 0)");
2625
}
@@ -99,7 +98,9 @@ void server_base::handle_stop() {
9998

10099
server::server(const server_settings & settings, request_handler & user_request_handler) :
101100
server_base(settings, user_request_handler) {
102-
//_log.Log(LOG_STATUS, "[web:%s] create server using settings : %s", settings.listening_port.c_str(), settings.to_string().c_str());
101+
#ifdef _DEBUG
102+
_log.Log(LOG_STATUS, "[web:%s] create server using settings : %s", settings.listening_port.c_str(), settings.to_string().c_str());
103+
#endif
103104
init(boost::bind(&server::init_connection, this),
104105
boost::bind(&server::handle_accept, this, _1));
105106
}
@@ -132,7 +133,9 @@ ssl_server::ssl_server(const ssl_server_settings & ssl_settings, request_handler
132133
settings_(ssl_settings),
133134
context_(io_service_, ssl_settings.get_ssl_method())
134135
{
135-
//_log.Log(LOG_STATUS, "[web:%s] create ssl_server using ssl_server_settings : %s", ssl_settings.listening_port.c_str(), ssl_settings.to_string().c_str());
136+
#ifdef _DEBUG
137+
_log.Log(LOG_STATUS, "[web:%s] create ssl_server using ssl_server_settings : %s", ssl_settings.listening_port.c_str(), ssl_settings.to_string().c_str());
138+
#endif
136139
init(boost::bind(&ssl_server::init_connection, this),
137140
boost::bind(&ssl_server::handle_accept, this, _1));
138141
}
@@ -142,13 +145,14 @@ ssl_server::ssl_server(const server_settings & settings, request_handler & user_
142145
server_base(settings, user_request_handler),
143146
settings_(dynamic_cast<ssl_server_settings const &>(settings)),
144147
context_(io_service_, dynamic_cast<ssl_server_settings const &>(settings).get_ssl_method()) {
145-
//_log.Log(LOG_STATUS, "[web:%s] create ssl_server using server_settings : %s", settings.listening_port.c_str(), settings.to_string().c_str());
148+
#ifdef _DEBUG
149+
_log.Log(LOG_STATUS, "[web:%s] create ssl_server using server_settings : %s", settings.listening_port.c_str(), settings.to_string().c_str());
150+
#endif
146151
init(boost::bind(&ssl_server::init_connection, this),
147152
boost::bind(&ssl_server::handle_accept, this, _1));
148153
}
149154

150155
void ssl_server::init_connection() {
151-
//_log.Log(LOG_STATUS, "[web:%s] ssl_server::init_connection() : new connection using settings : %s", settings_.listening_port.c_str(), settings_.to_string().c_str());
152156

153157
new_connection_.reset(new connection(io_service_, connection_manager_, request_handler_, timeout_, context_));
154158

@@ -202,7 +206,9 @@ void ssl_server::init_connection() {
202206
(std::istreambuf_iterator<char>()));
203207
if (content.find("BEGIN DH PARAMETERS") != std::string::npos) {
204208
context_.use_tmp_dh_file(settings_.tmp_dh_file_path);
205-
//_log.Log(LOG_STATUS, "[web:%s] 'BEGIN DH PARAMETERS' found in file %s", settings_.listening_port.c_str(), settings_.tmp_dh_file_path.c_str());
209+
#ifdef _DEBUG
210+
_log.Log(LOG_STATUS, "[web:%s] 'BEGIN DH PARAMETERS' found in file %s", settings_.listening_port.c_str(), settings_.tmp_dh_file_path.c_str());
211+
#endif
206212
} else {
207213
_log.Log(LOG_ERROR, "[web:%s] missing SSL DH parameters from file %s", settings_.listening_port.c_str(), settings_.tmp_dh_file_path.c_str());
208214
}

0 commit comments

Comments
 (0)