繁体   English   中英

如何将cURL详细输出通过管道发送到日志记录模块?

[英]How to pipe cURL verbose output to logging module?

有谁知道如何或是否有可能将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()

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM