Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/315.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何将cURL详细输出管道化到日志模块?_Python_Curl - Fatal编程技术网

Python 如何将cURL详细输出管道化到日志模块?

Python 如何将cURL详细输出管道化到日志模块?,python,curl,Python,Curl,有人知道如何或是否有可能将cURL详细输出重定向到日志模块吗?现在详细的输出都将发送到stdout,但我想通过管道将其发送到logging.debug,它将保存到一个文件中 请注意,我不想将所有控制台输出通过管道传输到日志记录。另外,我确实有一个字符串缓冲区来捕获pycurl.WRITEFUNCTION,但是它似乎没有捕获详细的输出 当前代码: logging.debug('starting setopt_put for url: %s',api_url) self._podium_curl_s

有人知道如何或是否有可能将cURL详细输出重定向到日志模块吗?现在详细的输出都将发送到stdout,但我想通过管道将其发送到logging.debug,它将保存到一个文件中

请注意,我不想将所有控制台输出通过管道传输到日志记录。另外,我确实有一个字符串缓冲区来捕获pycurl.WRITEFUNCTION,但是它似乎没有捕获详细的输出

当前代码:

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
选项类似,只是它是通过详细输出而不是响应体调用的

有参考信息和一个简短的示例,您应该能够根据自己的需要进行调整:

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

你现在做得怎么样?
stdout
是什么意思,您在哪里调用curl?为我现在的操作添加了代码,WRITEFUNCTION参数捕获常规curl输出,但详细信息仅使其进入stdout/console,它不会进入相同的字符串缓冲区,然后可以根据需要使用