简体   繁体   English

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

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

Does anyone know how or if it's possible to redirect cURL verbose output to the logging module? 有谁知道如何或是否有可能将cURL详细输出重定向到日志记录模块? Right now the verbose output is all going to stdout, but I'd like to pipe it to logging.debug which is being saved to a file. 现在,详细的输出将全部输出到stdout,但是我想将其通过管道发送到logging.debug中,该文件将被保存到文件中。

Note that I don't want to pipe all console output to logging. 请注意,我不想将所有控制台输出传递给日志记录。 Also, I do have a string buffer to capture the pycurl.WRITEFUNCTION however that doesn't seem to capture the VERBOSE output. 另外,我确实有一个字符串缓冲区来捕获pycurl.WRITEFUNCTION,但是似乎没有捕获VERBOSE输出。

current code: 当前代码:

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())

Thanks! 谢谢!

curl has a DEBUGFUNCTION callback option that works in a similar way to the WRITEFUNCTION option, except that it gets called with the VERBOSE output instead of the response body. curl具有DEBUGFUNCTION回调选项,该选项与WRITEFUNCTION选项的工作方式类似,不同之处在于,它使用VERBOSE输出而不是响应主体进行调用。

The official documentation has reference information as well as a short example, which you should be able to adapt to your needs: 官方文档提供了参考信息以及一个简短的示例,您应该可以根据自己的需要进行调整:

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