Browse Source

use macros do disable logging when non-debug built.

JSON-192
roker 7 months ago
parent
commit
9bdb84e2be
3 changed files with 19 additions and 19 deletions
  1. +3
    -3
      server/ev_server.cc
  2. +3
    -3
      server/function_map.hh
  3. +13
    -13
      server/json-adapter.cc

+ 3
- 3
server/ev_server.cc View File

@ -240,7 +240,7 @@ ev_server::ev_server(const std::string& address, unsigned short port, bool deliv
pEp::Webserver::response ev_server::sendReplyString(const pEp::Webserver::request& req, const char* contentType, std::string&& outputText)
{
Log() << Logger::Debug << "sendReplyString(): "
DEBUG_LOG(Log()) << "sendReplyString(): "
<< ", contentType=" << (contentType ? "«" + std::string(contentType)+ "»" : "NULL")
<< ", output.size()=«" << outputText.size() << "»"
<< ", keep_alive=" << req.keep_alive() << ".";
@ -284,13 +284,13 @@ pEp::Webserver::response ev_server::OnOtherRequest(boost::cmatch match, const pE
const std::string path = req.target().to_string(); // NB: is percent-encoded! does not relevant for the supported paths above.
Log() << Logger::Debug << "** Request: [" << req.method_string().to_string() << "] " << "Path: [" + path + "]";
DEBUG_LOG( Log() ) << "** Request: [" << req.method_string().to_string() << "] " << "Path: [" + path + "]";
try{
const auto q = files.find(path);
if(q != files.end()) // found in "files" map
{
Log() << Logger::Debug << "\t found file \"" << q->second.fileName.string() << "\", type=" << q->second.mimeType << ".\n";
DEBUG_LOG(Log()) << "\t found file \"" << q->second.fileName.string() << "\", type=" << q->second.mimeType << ".\n";
return sendFile( req, q->second.mimeType, q->second.fileName);
}


+ 3
- 3
server/function_map.hh View File

@ -247,7 +247,7 @@ public:
// FIXME: Does only work with functions with type: void(PEP_SESSION, T):
const auto p1 = from_json< typename std::tuple_element<1, param_tuple_t>::type >(parameters[0]);
Log << Logger::Debug << "func_name=\"" << func_name << "\", value=" << p1 << ".";
DEBUG_LOG(Log) << "func_name=\"" << func_name << "\", value=" << p1 << ".";
std::function<void(PEP_SESSION)> func = std::bind(Base::fn, std::placeholders::_1, p1);
context->cache(func_name, func);
@ -277,7 +277,7 @@ public:
Logger Log("FuncCachePasswd::call");
const std::string& passphrase = parameters.at(0).get_str();
Log << Logger::Debug << "func_name=\"" << func_name << "\", value is confidential. ";
DEBUG_LOG(Log) << "func_name=\"" << func_name << "\", value is confidential. ";
pEp::passphrase_cache.add(passphrase); // for the current PEP_SESSION
std::function<void(PEP_SESSION)> func = [passphrase](PEP_SESSION session)
@ -312,7 +312,7 @@ public:
bool enable = parameters.at(0).get_bool();
const std::string& passphrase = parameters.at(1).get_str();
Log << Logger::Debug << "func_name=\"" << func_name << "\", value is confidential. ";
DEBUG_LOG(Log) << "func_name=\"" << func_name << "\", value is confidential.";
pEp::passphrase_cache.add_stored(passphrase); // for the current PEP_SESSION
std::function<void(PEP_SESSION)> func = [enable, passphrase](PEP_SESSION session)


+ 13
- 13
server/json-adapter.cc View File

@ -111,7 +111,7 @@ struct JsonAdapter::Internal
~Internal()
{
Log << Logger::Debug << "~JAI";
DEBUG_LOG(Log) << "~JAI";
}
@ -138,13 +138,13 @@ struct JsonAdapter::Internal
const std::string request_r = js::write(request);
Lock L(_mtx);
Log << Logger::Debug << "makeAndDeliverRequest: \n"
DEBUG_LOG(Log) << "makeAndDeliverRequest: \n"
"Request: " << request_r << "\n"
"Goes to " << eventListener.size() << " listener(s).";
for(auto& e : eventListener)
{
Log << Logger::Debug << " ~~~ " << to_log(e.first) << " has " << e.second.Q->size() << " old events waiting.";
DEBUG_LOG(Log) << " ~~~ " << to_log(e.first) << " has " << e.second.Q->size() << " old events waiting.";
e.second.Q->push_back(request);
}
}
@ -290,7 +290,7 @@ try
Logger L("JA:run");
L << Logger::Info << "This is " << (void*)this << ", thread id " << std::this_thread::get_id() << ".";
L << Logger::Debug << "Registry:\n" << i->session_registry->to_string();
DEBUG_LOG(L) << "Registry:\n" << i->session_registry->to_string();
i->running = true;
i->webserver->run();
@ -307,7 +307,7 @@ void JsonAdapter::connection_close_cb()
Lock L{_mtx};
const auto tid = std::this_thread::get_id();
auto q = i->eventListener.find( tid );
i->Log << Logger::Debug << "Connection Close Callback: " << (q==i->eventListener.end() ? "NO" : "1") << " entry in eventListener map for Thread " << tid << ".";
DEBUG_LOG(i->Log) << "Connection Close Callback: " << (q==i->eventListener.end() ? "NO" : "1") << " entry in eventListener map for Thread " << tid << ".";
if(q != i->eventListener.end())
{
i->Log.debug("%d listener(s) waiting on event queue", q->second.Q->waiting());
@ -325,10 +325,10 @@ void JsonAdapter::close_session(const std::string& session_id)
{
Lock L{_mtx};
auto q = i->eventListener.find( session_id );
i->Log << Logger::Debug << "Close session \"" << session_id << "\": " << (q==i->eventListener.end() ? "NO" : "1") << " entry in eventListener map for session_id \"" << session_id << "\".";
DEBUG_LOG(i->Log) << "Close session \"" << session_id << "\": " << (q==i->eventListener.end() ? "NO" : "1") << " entry in eventListener map for session_id \"" << session_id << "\".";
if(q != i->eventListener.end())
{
i->Log.debug("%d listener(s) waiting on event queue", q->second.Q->waiting());
DEBUG_OUT(i->Log, "%d listener(s) waiting on event queue", q->second.Q->waiting());
while(q->second.Q->waiting() > 0)
{
q->second.Q->push_back(queue_close_event);
@ -398,32 +398,32 @@ js::Array JsonAdapter::Internal::pollForEvents(const EventListenerKey& key, unsi
const size_t size = elQ->size();
if(size)
{
L << Logger::Debug << size << " events in queue for key " << to_log(key) << ":";
DEBUG_LOG(L) << size << " events in queue for key " << to_log(key) << ":";
// fetch all elements from queue
for(size_t i=0; i<size; ++i)
{
js::Object obj{ elQ->pop_front() };
const std::string obj_s = js::write( obj );
L << Logger::Debug << "\t#" << i << ": " << obj_s;
DEBUG_LOG(L) << "\t#" << i << ": " << obj_s;
arr.emplace_back( std::move(obj) );
}
}else{
// block until there is at least one element or timeout
L << Logger::Debug << "Queue for key " << to_log(key) << " is empty. I'll block for " << timeout_seconds << " seconds.";
DEBUG_LOG(L) << "Queue for key " << to_log(key) << " is empty. I'll block for " << timeout_seconds << " seconds.";
js::Object event;
const bool success = elQ->try_pop_front( event, std::chrono::seconds(timeout_seconds) );
if(success)
{
const std::string event_s = js::write(event);
L << Logger::Debug << "Success! Got this event: " << event_s ;
DEBUG_LOG(L) << "Success! Got this event: " << event_s ;
arr.emplace_back( std::move(event) );
}else{
L << Logger::Debug << "Timeout. No event after " << timeout_seconds << " seconds arrived. So sad.";
DEBUG_LOG(L) << "Timeout. No event after " << timeout_seconds << " seconds arrived. So sad.";
}
}
L << Logger::Debug << "Return array with " << arr.size() << " elements.";
DEBUG_LOG(L) << "Return array with " << arr.size() << " elements.";
return arr;
}


Loading…
Cancel
Save