2

I am using Django 1.9 to expose SOAP 1.1 API with Spyne version 2.12.16

I need to implement logging for every request XML and response XML in my platform.

Django urls.py is

url(r'^your_data/', DjangoView.as_view(
        name="YourDataService",
        services=[YourDataService],
        tns='http://127.0.0.1:8000/',
        in_protocol=Soap11(validator='lxml'),
        out_protocol=Soap11()))

views.py:

from spyne.decorator import rpc
from spyne.model.primitive import String, AnyDict
from spyne.service import ServiceBase

class YourDataService(ServiceBase):
    @rpc(String, String, String, _returns=AnyDict)
    def call_this_method(self, a, b, c):
        return {'aa': 'OK','bb': 'Great','cc': 'Perfect'}

I read somewhere, overriding call_wrapper method of Spyne ServiceBase class can log request and response XML data for that service. But implementing the same resulted in weird logging etc issues:

class ServiceBaseAbstract(ServiceBase):
    def call_wrapper(cls, ctx):
        try:
            return ctx.service_class.call_wrapper(ctx)
        except Exception as err:
            print err

It gives an error:

No handlers could be found for logger "spyne.application.server"

API works fine without overriding call_wrapper.

I am really confused and can't find a way out of this. Your help will be much appreciated. Thank you

  • 1
    That's not an error, it's a warning, and it doesn't come from Spyne but comes from Python's logging infrastructure. You need to configure Python logging to see *any* log messages. – Burak Arslan Feb 28 '20 at 07:11

1 Answers1

2

Overriding call_wrapper is to alter the way exceptions are handled / logged by Spyne.

Instead, you should configure the python logging library to display DEBUG-level messages and also enable protocol debug logging for Spyne.

logging.getLogger('').setLevel(logging.DEBUG)        
logging.getLogger('spyne.protocol.xml').setLevel(logging.DEBUG)
Burak Arslan
  • 7,671
  • 2
  • 15
  • 24
  • 1
    I had logger issues while overriding ServiceBase class `from spyne.service import ServiceBase`. Instead, I have to override from Application Class `from spyne.application import Application` to make it work, which looks like this `try: ctx_call_wrapper_res = super(MyApplication, self).call_wrapper(ctx) except Exception, e: pass # custom code` – Saurabh Chopra Feb 28 '20 at 10:11