<div dir="ltr"><div dir="ltr">Hi Even,</div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Fri, Feb 8, 2019 at 4:59 AM Even Rouault <<a href="mailto:even.rouault@spatialys.com">even.rouault@spatialys.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">> Actually, what I had in mind (thinking out loud) would sit solely<br>
> within GDAL, e.g. a method to globally specify a callback function to<br>
> be called whenever GDAL creates a network request, e.g. within<br>
> CPLHTTPFetchEx (and similarly for replies).<br>
<br>
CPLHTTPFetchEx() is just one of the site that does network access. <br>
cpl_vsil_curl.cpp, cpl_vsil_s3.cpp, cpl_vsil_az.cpp, cpl_vsil_swift.cpp, <br>
cpl_vsil_webhdfs.cpp also do network access<br>
<br>
But at the end of all them must go through CPLHTTPSetOptions() in cpl_http.cpp<br>
<br>
> (With clients being<br>
> responsible for ensuring that their callback functions are<br>
> appropriately thread safe).<br>
> <br>
> Does this sound desirable? Any concerns/blockers before I start hacking on<br>
> it?<br>
<br>
I had several thoughts about this<br>
<br>
1) yes a dedicated callback mechanism could work of course<br>
<br>
2) As Sean mentionned, and provided we redirect curl logging to our own <br>
callbacks instead of stderr, we could potentially just use the CPLDebug() <br>
infrastructure with the the callback being installed with CPLSetErrorHandler() <br>
+ CPLSetCurrentErrorHandlerCatchDebug(true). We probably wouldn't want so much <br>
debugging information to be emitted by default (both because of verbosity and <br>
performance), so this should still be conditionalized by the <br>
CPL_CURL_VERBOSE=YES config option/env. variable<br>
<br>
3) An alternative would be to have a dedicated generic logging API<br>
<br>
void CPLLogEvent(const char* topic, const char* fmt, ...);<br>
<br>
int CPLHasLoggerFor(const char* topic);<br>
<br>
typedef void (*CPLLoggerCallback)(const char* topic,<br>
const char* msg, void* user_data);<br>
<br>
void* CPLInstallLogger(const char* topic,<br>
CPLLoggerCallback cbk, void* user_data);<br>
void CPLUninstallLogger(void*);<br>
<br>
but I'm wondering if there wouldn't be too much confusion/intersection with <br>
the CPLDebug() mechanism.<br>
<br>
<br>
My current slight preference would go to 2) to reuse existing infrastructure. <br>
Maybe others, including Robert CC'ed who has hacked in the error/debug area <br>
recently, have thoughts on this.<br>
<br>
<br>
Even<br></blockquote><div><br></div><div>I'd prefer to see the existing infrastructure reused because then some logging of network activity would automatically appear for users of Rasterio (which already subscribes to CPLDebug messages).</div><div><br></div><div>I think the right amount of default logging would be to call CPLDebug for new connections and report the URL, but not necessarily call CPLDebug for every request made using that connection.</div><div><br></div></div>-- <br><div dir="ltr" class="gmail_signature"><div dir="ltr">Sean Gillies</div></div></div>