vmware / pyvmomi

VMware vSphere API Python Bindings
Apache License 2.0
2.19k stars 766 forks source link

Request and response logging #1045

Open IvarVirusiim opened 11 months ago

IvarVirusiim commented 11 months ago

Is your feature request related to a problem? Please describe.

It's sometimes unclear why some requests fail. When there would be a possibility to log all requests and response, that move between SDK and vCenter, would make debugging easier. Since the amount of data can be big and many requests aren't relevant, a way to filter (include or exclude requests/responses by name) would be appreciated.

Describe the solution you'd like

Standard python logging would be preferred. The solution should have a way to configure, which requests and responses are being logged (include or exclude by name)

Describe alternatives you've considered

If there would be a way to add custom hooks for pyVmomi.SoapAdapter.SoapStubAdapter.InvokeMethod, then user could decide how the logging is done. Those would be then passed on through the connection (ServiceInstance)

Example:

    def InvokeMethod(self, mo, info, args, outerStub=None, request_logger=None, response_logger=None):

...

        try:
            request_logger(mo)
        except:
            ...
        req = self.SerializeRequest(mo, info, args)

...



            conn.request('POST', self.path, req, headers)
            resp = conn.getresponse()
            try:
                response_logger(resp)
            except:
                ...