forked from loafle/openapi-generator-original
Add logging and debug report for python client.
This commit is contained in:
parent
d97b0984cb
commit
8a3c64aa41
@ -1,6 +1,9 @@
|
|||||||
from __future__ import absolute_import
|
from __future__ import absolute_import
|
||||||
import base64
|
import base64
|
||||||
import urllib3
|
import urllib3
|
||||||
|
import httplib
|
||||||
|
import sys
|
||||||
|
import logging
|
||||||
|
|
||||||
def get_api_key_with_prefix(key):
|
def get_api_key_with_prefix(key):
|
||||||
global api_key
|
global api_key
|
||||||
@ -11,6 +14,22 @@ def get_api_key_with_prefix(key):
|
|||||||
elif api_key.get(key):
|
elif api_key.get(key):
|
||||||
return api_key[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():
|
def get_basic_auth_token():
|
||||||
global username
|
global username
|
||||||
global password
|
global password
|
||||||
@ -50,3 +69,9 @@ password = ''
|
|||||||
|
|
||||||
# Temp foloder for file download
|
# Temp foloder for file download
|
||||||
temp_folder_path = None
|
temp_folder_path = None
|
||||||
|
|
||||||
|
# Logging settings
|
||||||
|
logging_file = None
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -10,6 +10,7 @@ import io
|
|||||||
import json
|
import json
|
||||||
import ssl
|
import ssl
|
||||||
import certifi
|
import certifi
|
||||||
|
import logging
|
||||||
|
|
||||||
# python 2 and python 3 compatibility library
|
# python 2 and python 3 compatibility library
|
||||||
from six import iteritems
|
from six import iteritems
|
||||||
@ -27,6 +28,9 @@ except ImportError:
|
|||||||
from urllib import urlencode
|
from urllib import urlencode
|
||||||
|
|
||||||
|
|
||||||
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
class RESTResponse(io.IOBase):
|
class RESTResponse(io.IOBase):
|
||||||
|
|
||||||
def __init__(self, resp):
|
def __init__(self, resp):
|
||||||
@ -125,6 +129,15 @@ class RESTClientObject(object):
|
|||||||
headers=headers)
|
headers=headers)
|
||||||
r = RESTResponse(r)
|
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.
|
# In the python 3, the response.data is bytes.
|
||||||
# we need to decode it to string.
|
# we need to decode it to string.
|
||||||
if sys.version_info > (3,):
|
if sys.version_info > (3,):
|
||||||
|
@ -1,6 +1,9 @@
|
|||||||
from __future__ import absolute_import
|
from __future__ import absolute_import
|
||||||
import base64
|
import base64
|
||||||
import urllib3
|
import urllib3
|
||||||
|
import httplib
|
||||||
|
import sys
|
||||||
|
import logging
|
||||||
|
|
||||||
def get_api_key_with_prefix(key):
|
def get_api_key_with_prefix(key):
|
||||||
global api_key
|
global api_key
|
||||||
@ -11,6 +14,22 @@ def get_api_key_with_prefix(key):
|
|||||||
elif api_key.get(key):
|
elif api_key.get(key):
|
||||||
return api_key[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():
|
def get_basic_auth_token():
|
||||||
global username
|
global username
|
||||||
global password
|
global password
|
||||||
@ -41,5 +60,10 @@ api_key_prefix = {}
|
|||||||
username = ''
|
username = ''
|
||||||
password = ''
|
password = ''
|
||||||
|
|
||||||
|
<<<<<<< HEAD
|
||||||
# Temp foloder for file download
|
# Temp foloder for file download
|
||||||
temp_folder_path = None
|
temp_folder_path = None
|
||||||
|
=======
|
||||||
|
# Logging settings
|
||||||
|
logging_file = None
|
||||||
|
>>>>>>> Add logging and debug report for python client.
|
||||||
|
@ -10,6 +10,7 @@ import io
|
|||||||
import json
|
import json
|
||||||
import ssl
|
import ssl
|
||||||
import certifi
|
import certifi
|
||||||
|
import logging
|
||||||
|
|
||||||
# python 2 and python 3 compatibility library
|
# python 2 and python 3 compatibility library
|
||||||
from six import iteritems
|
from six import iteritems
|
||||||
@ -27,6 +28,9 @@ except ImportError:
|
|||||||
from urllib import urlencode
|
from urllib import urlencode
|
||||||
|
|
||||||
|
|
||||||
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
class RESTResponse(io.IOBase):
|
class RESTResponse(io.IOBase):
|
||||||
|
|
||||||
def __init__(self, resp):
|
def __init__(self, resp):
|
||||||
@ -125,6 +129,18 @@ class RESTClientObject(object):
|
|||||||
headers=headers)
|
headers=headers)
|
||||||
r = RESTResponse(r)
|
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.
|
# In the python 3, the response.data is bytes.
|
||||||
# we need to decode it to string.
|
# we need to decode it to string.
|
||||||
if sys.version_info > (3,):
|
if sys.version_info > (3,):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user