Browse Source

compile-time removal of certain (possibly long) debug log messages in stream format via new macro DEBUG_LOG()

JSON-152
Roker 2 years ago
parent
commit
3590c9604e
3 changed files with 22 additions and 4 deletions
  1. +9
    -4
      server/ev_server.cc
  2. +2
    -0
      server/logger.cc
  3. +11
    -0
      server/logger.hh

+ 9
- 4
server/ev_server.cc View File

@ -183,8 +183,9 @@ pEp::Webserver::response ev_server::sendReplyString(const pEp::Webserver::reques
Log() << Logger::Debug << "sendReplyString(): "
<< ", contentType=" << (contentType ? "«" + std::string(contentType)+ "»" : "NULL")
<< ", output.size()=«" << outputText.size() << "»"
<< ", keep_alive=" << req.keep_alive() << ",\n"
<< "outputText=«" << outputText << "»";
<< ", keep_alive=" << req.keep_alive() << ".";
DEBUG_LOG(Log()) << "outputText=«" << outputText << "»";
pEp::Webserver::response res{pEp::http::status::ok, req.version()};
res.set(pEp::http::field::content_type, contentType);
@ -303,14 +304,18 @@ pEp::Webserver::response ev_server::OnApiRequest(boost::cmatch match, const pEp:
const std::string data_string = req.body();
if(!data_string.empty())
{
L << Logger::Debug << "Data: «" << data_string << "»";
#ifdef DEBUG_ENABLED
L << Logger::Debug << "Data: «" << data_string << "» (" << data_string.size() << " bytes).";
#else
L << Logger::Debug << "Data.size=" << data_string.size() << ".";
#endif
bool b = js::read( data_string, p);
if(p.type() == js::obj_type)
{
const js::Object& request = p.get_obj();
answer = call( functions, request, &ja );
}else{
const std::string error_msg = "evbuffer_copyout does not return a JSON string. b=" + std::to_string(b);
const std::string error_msg = "request body is not a JSON object. js::read() returned" + std::to_string(b);
L << Logger::Error << error_msg;
answer = make_error( JSON_RPC::PARSE_ERROR, error_msg, js::Value{data_string}, 42 );
}


+ 2
- 0
server/logger.cc View File

@ -382,6 +382,8 @@ LOGGER_LAZY( debugInternal , DebugInternal )
#else
// intentionally left blank.
// the methods are already defined as do-nothing inline functions in Logger.hh
const NullLogger nulllogger{}; // to make linker happy.
#endif
#undef LOGGER_LAZY


+ 11
- 0
server/logger.hh View File

@ -8,9 +8,20 @@
#ifdef DEBUG_ENABLED
#define DEBUG_OUT( LL , ... ) LL.debug( __VA_ARGS__ )
#define DEBUGI_OUT( LL , ... ) LL.debugInternal( __VA_ARGS__ )
#define DEBUG_LOG( LL ) ( (LL) << Logger::Debug )
#else
struct NullLogger {};
template<class T>
const NullLogger& operator<<(const NullLogger& nl, const T&) { return nl; }
extern const NullLogger nulllogger;
#define DEBUG_OUT(...) do{}while(0)
#define DEBUGI_OUT(...) do{}while(0)
#define DEBUG_LOG( LL ) nulllogger
#endif
#ifdef __GNUC__


Loading…
Cancel
Save