Skip to content

Commit

Permalink
WebServer: write messages from MHD to log
Browse files Browse the repository at this point in the history
  • Loading branch information
Karlson2k committed Feb 15, 2015
1 parent 028c55c commit a74f0c6
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions xbmc/network/WebServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1035,6 +1035,27 @@ void CWebServer::ContentReaderFreeCallback(void *cls)
#endif
}

// local helper
static void logFromMHD(void* unused, const char* fmt, va_list ap)
{
if (fmt == NULL || fmt[0] == 0)
CLog::Log(LOGERROR, "CWebServer: MHD reported error with empty string");
else
{
std::string errDsc = StringUtils::FormatV(fmt, ap);
if (errDsc.empty())
CLog::Log(LOGERROR, "CWebServer: MHD reported error with unprintable string \"%s\"", fmt);
else
{
if (errDsc.at(errDsc.length() - 1) == '\n')
errDsc.erase(errDsc.length() - 1);

// Most common error is "aborted connection", so log it at LOGDEBUG level
CLog::Log(LOGDEBUG, "CWebServer [MHD]: %s", errDsc.c_str());
}
}
}

struct MHD_Daemon* CWebServer::StartMHD(unsigned int flags, int port)
{
unsigned int timeout = 60 * 60 * 24;
Expand All @@ -1050,6 +1071,9 @@ struct MHD_Daemon* CWebServer::StartMHD(unsigned int flags, int port)
// otherwise on libmicrohttpd 0.4.4-1 it spins a busy loop
MHD_USE_THREAD_PER_CONNECTION
#endif
#if (MHD_VERSION >= 0x00040001)
| MHD_USE_DEBUG /* Print MHD error messages to log */
#endif
,
port,
NULL,
Expand All @@ -1063,6 +1087,9 @@ struct MHD_Daemon* CWebServer::StartMHD(unsigned int flags, int port)
MHD_OPTION_CONNECTION_LIMIT, 512,
MHD_OPTION_CONNECTION_TIMEOUT, timeout,
MHD_OPTION_URI_LOG_CALLBACK, &CWebServer::UriRequestLogger, this,
#if (MHD_VERSION >= 0x00040001)
MHD_OPTION_EXTERNAL_LOGGER, &logFromMHD, NULL,
#endif // MHD_VERSION >= 0x00040001
MHD_OPTION_END);
}

Expand Down

0 comments on commit a74f0c6

Please sign in to comment.