diff --git a/modules/swagger-codegen/src/main/resources/python/configuration.mustache b/modules/swagger-codegen/src/main/resources/python/configuration.mustache index 2dd1045307f..a8065705fb4 100644 --- a/modules/swagger-codegen/src/main/resources/python/configuration.mustache +++ b/modules/swagger-codegen/src/main/resources/python/configuration.mustache @@ -1,6 +1,9 @@ from __future__ import absolute_import import base64 import urllib3 +import httplib +import sys +import logging def get_api_key_with_prefix(key): global api_key @@ -11,6 +14,22 @@ def get_api_key_with_prefix(key): elif api_key.get(key): return api_key[key] +def setting_logging_enabled(): + global logging_file + format = '%(asctime)s %(levelname)s %(message)s' + if logging_file: + logging.basicConfig(filename=logging_file, level=logging.DEBUG, format=format) + else: + logging.basicConfig(stream=sys.stdout, level=logging.DEBUG, format=format) + httplib.HTTPConnection.debuglevel = 1 + +def to_debug_report(): + return "Python SDK Debug Report:\n"\ + "OS: {env}\n"\ + "Python Version: {pyversion}\n"\ + "Version of the API: {{version}}\n"\ + "SDK Package Version: {{packageVersion}}".format(env=sys.platform, pyversion=sys.version) + def get_basic_auth_token(): global username global password @@ -50,3 +69,9 @@ password = '' # Temp foloder for file download temp_folder_path = None + +# Logging settings +logging_file = None + + + diff --git a/modules/swagger-codegen/src/main/resources/python/rest.mustache b/modules/swagger-codegen/src/main/resources/python/rest.mustache index 25cf702766e..a5290d7225a 100644 --- a/modules/swagger-codegen/src/main/resources/python/rest.mustache +++ b/modules/swagger-codegen/src/main/resources/python/rest.mustache @@ -10,6 +10,7 @@ import io import json import ssl import certifi +import logging # python 2 and python 3 compatibility library from six import iteritems @@ -27,6 +28,9 @@ except ImportError: from urllib import urlencode +logger = logging.getLogger(__name__) + + class RESTResponse(io.IOBase): def __init__(self, resp): @@ -125,6 +129,15 @@ class RESTClientObject(object): headers=headers) r = RESTResponse(r) + # log response body + logger.debug("response body: %s" % r.data) + + if r.status not in range(200, 206): + raise ApiException(r) + + return self.process_response(r) + + def process_response(self, response): # In the python 3, the response.data is bytes. # we need to decode it to string. if sys.version_info > (3,): diff --git a/samples/client/petstore/python/swagger_client/configuration.py b/samples/client/petstore/python/swagger_client/configuration.py index 7b6f4023914..2ae779e5b22 100644 --- a/samples/client/petstore/python/swagger_client/configuration.py +++ b/samples/client/petstore/python/swagger_client/configuration.py @@ -1,6 +1,9 @@ from __future__ import absolute_import import base64 import urllib3 +import httplib +import sys +import logging def get_api_key_with_prefix(key): global api_key @@ -11,6 +14,22 @@ def get_api_key_with_prefix(key): elif api_key.get(key): return api_key[key] +def setting_logging_enabled(): + global logging_file + format = '%(asctime)s %(levelname)s %(message)s' + if logging_file: + logging.basicConfig(filename=logging_file, level=logging.DEBUG, format=format) + else: + logging.basicConfig(stream=sys.stdout, level=logging.DEBUG, format=format) + httplib.HTTPConnection.debuglevel = 1 + +def to_debug_report(): + return "Python SDK Debug Report:\n"\ + "OS: {env}\n"\ + "Python Version: {pyversion}\n"\ + "Version of the API: 1.0.0\n"\ + "SDK Package Version: 1.0.0".format(env=sys.platform, pyversion=sys.version) + def get_basic_auth_token(): global username global password @@ -41,5 +60,10 @@ api_key_prefix = {} username = '' password = '' +<<<<<<< HEAD # Temp foloder for file download temp_folder_path = None +======= +# Logging settings +logging_file = None +>>>>>>> Add logging and debug report for python client. diff --git a/samples/client/petstore/python/swagger_client/rest.py b/samples/client/petstore/python/swagger_client/rest.py index 25cf702766e..2759e754fd2 100644 --- a/samples/client/petstore/python/swagger_client/rest.py +++ b/samples/client/petstore/python/swagger_client/rest.py @@ -10,6 +10,7 @@ import io import json import ssl import certifi +import logging # python 2 and python 3 compatibility library from six import iteritems @@ -27,6 +28,9 @@ except ImportError: from urllib import urlencode +logger = logging.getLogger(__name__) + + class RESTResponse(io.IOBase): def __init__(self, resp): @@ -125,6 +129,18 @@ class RESTClientObject(object): headers=headers) r = RESTResponse(r) +<<<<<<< HEAD +======= + # log response body + logger.debug("response body: %s" % r.data) + + if r.status not in range(200, 206): + raise ApiException(r) + + return self.process_response(r) + + def process_response(self, response): +>>>>>>> Add logging and debug report for python client. # In the python 3, the response.data is bytes. # we need to decode it to string. if sys.version_info > (3,):