Logging: curl - write debug output through MPD log instead of curl writing directly to stderr.
The output gets the standard MPD log format with domain curl and a timestamp. Using CURLOPT_DEBUGFUNCTION that is only called when CURLOPT_VERBOSE is in effect when MPD log level is verbose.
This commit is contained in:
parent
bddfff9c2b
commit
f15b6a43d3
@ -414,7 +414,7 @@ input_curl_init(EventLoop &event_loop, const ConfigBlock &block)
|
||||
std::chrono::seconds{1},
|
||||
default_connection_timeout));
|
||||
|
||||
verbose = block.GetBlockValue("verbose",verbose);
|
||||
verbose = block.GetBlockValue("verbose", verbose);
|
||||
|
||||
low_speed_limit = block.GetBlockValue("low_speed_limit", default_low_speed_limit);
|
||||
|
||||
@ -436,6 +436,31 @@ input_curl_finish() noexcept
|
||||
http_200_aliases = nullptr;
|
||||
}
|
||||
|
||||
/**
|
||||
* CURLOPT_DEBUGFUNCTION
|
||||
*/
|
||||
static int
|
||||
CurlDebugToLog(CURL *handle, curl_infotype type, char *data, size_t size, void *user)
|
||||
{
|
||||
(void)handle;
|
||||
(void)user;
|
||||
|
||||
switch(type) {
|
||||
case CURLINFO_TEXT:
|
||||
Log(LogLevel::DEBUG, curl_domain, std::string_view{data, size});
|
||||
break;
|
||||
case CURLINFO_HEADER_OUT:
|
||||
FmtDebug(curl_domain, "Header out: {}", std::string_view{data, size});
|
||||
break;
|
||||
case CURLINFO_HEADER_IN:
|
||||
FmtDebug(curl_domain, "Header in: {}", std::string_view{data, size});
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
template<typename I>
|
||||
inline
|
||||
CurlInputStream::CurlInputStream(EventLoop &event_loop, std::string_view _url,
|
||||
@ -513,6 +538,8 @@ CreateEasy(const char *url, struct curl_slist *headers)
|
||||
|
||||
easy.SetRequestHeaders(headers);
|
||||
|
||||
easy.SetOption(CURLOPT_DEBUGFUNCTION, CurlDebugToLog);
|
||||
|
||||
return easy;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user