有谁知道如何或是否有可能将cURL详细输出重定向到日志记录模块?现在,详细的输出将全部输出到stdout,但是我想将其输出到logging.debug并将其保存到文件中。
请注意,我不想将所有控制台输出通过管道传输到日志记录。另外,我确实有一个字符串缓冲区来捕获pycurl.WRITEFUNCTION,但是似乎没有捕获VERBOSE输出。
当前代码:
logging.debug('starting setopt_put for url: %s',api_url)
self._podium_curl_setopt_base(api_url.url + api_args)
self._podium_curl.setopt(pycurl.HTTPGET, 1)
self._podium_curl.setopt(pycurl.WRITEFUNCTION, self._string_buffer.write)
self._podium_curl.setopt(pycurl.VERBOSE, True)
self._podium_curl.perform()
logging.info(_string_buffer.getvalue())
谢谢!
curl具有一个DEBUGFUNCTION
回调选项,其功能与该WRITEFUNCTION
选项类似,不同之处在于它使用VERBOSE输出而不是响应主体进行调用。
在官方文件具有一定的参考信息,以及一个简单的例子,你应该能够适应您的需求:
def test(debug_type, debug_msg):
print "debug(%d): %s" % (debug_type, debug_msg)
c = pycurl.Curl()
c.setopt(pycurl.URL, "http://curl.haxx.se/")
c.setopt(pycurl.VERBOSE, 1)
c.setopt(pycurl.DEBUGFUNCTION, test)
c.perform()
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句