Skip to content

Commit f15b6a4

Browse files
committed
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.
1 parent bddfff9 commit f15b6a4

File tree

1 file changed

+28
-1
lines changed

1 file changed

+28
-1
lines changed

src/input/plugins/CurlInputPlugin.cxx

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -414,7 +414,7 @@ input_curl_init(EventLoop &event_loop, const ConfigBlock &block)
414414
std::chrono::seconds{1},
415415
default_connection_timeout));
416416

417-
verbose = block.GetBlockValue("verbose",verbose);
417+
verbose = block.GetBlockValue("verbose", verbose);
418418

419419
low_speed_limit = block.GetBlockValue("low_speed_limit", default_low_speed_limit);
420420

@@ -436,6 +436,31 @@ input_curl_finish() noexcept
436436
http_200_aliases = nullptr;
437437
}
438438

439+
/**
440+
* CURLOPT_DEBUGFUNCTION
441+
*/
442+
static int
443+
CurlDebugToLog(CURL *handle, curl_infotype type, char *data, size_t size, void *user)
444+
{
445+
(void)handle;
446+
(void)user;
447+
448+
switch(type) {
449+
case CURLINFO_TEXT:
450+
Log(LogLevel::DEBUG, curl_domain, std::string_view{data, size});
451+
break;
452+
case CURLINFO_HEADER_OUT:
453+
FmtDebug(curl_domain, "Header out: {}", std::string_view{data, size});
454+
break;
455+
case CURLINFO_HEADER_IN:
456+
FmtDebug(curl_domain, "Header in: {}", std::string_view{data, size});
457+
break;
458+
default:
459+
break;
460+
}
461+
return 0;
462+
}
463+
439464
template<typename I>
440465
inline
441466
CurlInputStream::CurlInputStream(EventLoop &event_loop, std::string_view _url,
@@ -513,6 +538,8 @@ CreateEasy(const char *url, struct curl_slist *headers)
513538

514539
easy.SetRequestHeaders(headers);
515540

541+
easy.SetOption(CURLOPT_DEBUGFUNCTION, CurlDebugToLog);
542+
516543
return easy;
517544
}
518545

0 commit comments

Comments
 (0)