20
20
from ._file_cache import OPTIONS_CACHE as OPTIONS_FILE_CACHE
21
21
22
22
23
+ logger = logging .getLogger (__name__ )
24
+
25
+
23
26
class VssClient (object ):
24
27
"""VssClient.
25
28
:param str base_url: Service URL
@@ -50,11 +53,11 @@ def _send_request(self, request, headers=None, content=None, **operation_config)
50
53
"""
51
54
if TRACE_ENV_VAR in os .environ and os .environ [TRACE_ENV_VAR ] == 'true' :
52
55
print (request .method + ' ' + request .url )
53
- logging .debug ('%s %s' , request .method , request .url )
54
- logging .debug ('Request content: %s' , content )
56
+ logger .debug ('%s %s' , request .method , request .url )
57
+ logger .debug ('Request content: %s' , content )
55
58
response = self ._client .send (request = request , headers = headers ,
56
59
content = content , ** operation_config )
57
- logging .debug ('Response content: %s' , response .content )
60
+ logger .debug ('Response content: %s' , response .content )
58
61
if response .status_code < 200 or response .status_code >= 300 :
59
62
self ._handle_error (request , response )
60
63
return response
@@ -71,11 +74,11 @@ def _send(self, http_method, location_id, version, route_values=None,
71
74
version )
72
75
73
76
if version != negotiated_version :
74
- logging .info ("Negotiated api version from '%s' down to '%s'. This means the client is newer than the server." ,
75
- version ,
76
- negotiated_version )
77
+ logger .info ("Negotiated api version from '%s' down to '%s'. This means the client is newer than the server." ,
78
+ version ,
79
+ negotiated_version )
77
80
else :
78
- logging .debug ("Api version '%s'" , negotiated_version )
81
+ logger .debug ("Api version '%s'" , negotiated_version )
79
82
80
83
# Construct headers
81
84
headers = {'Content-Type' : media_type + '; charset=utf-8' ,
@@ -112,7 +115,7 @@ def _create_request_message(self, http_method, location_id, route_values=None,
112
115
route_values ['resource' ] = location .resource_name
113
116
route_template = self ._remove_optional_route_parameters (location .route_template ,
114
117
route_values )
115
- logging .debug ('Route template: %s' , location .route_template )
118
+ logger .debug ('Route template: %s' , location .route_template )
116
119
url = self ._client .format_url (route_template , ** route_values )
117
120
request = ClientRequest ()
118
121
request .url = self ._client .format_url (url )
@@ -150,14 +153,14 @@ def _get_resource_locations(self, all_host_types):
150
153
# Next check for options cached on disk
151
154
if not all_host_types and OPTIONS_FILE_CACHE [self .normalized_url ]:
152
155
try :
153
- logging .debug ('File cache hit for options on: %s' , self .normalized_url )
156
+ logger .debug ('File cache hit for options on: %s' , self .normalized_url )
154
157
self ._locations = self ._base_deserialize .deserialize_data (OPTIONS_FILE_CACHE [self .normalized_url ],
155
158
'[ApiResourceLocation]' )
156
159
return self ._locations
157
160
except DeserializationError as ex :
158
- logging . exception ( str ( ex ) )
161
+ logger . debug ( ex , exc_info = True )
159
162
else :
160
- logging .debug ('File cache miss for options on: %s' , self .normalized_url )
163
+ logger .debug ('File cache miss for options on: %s' , self .normalized_url )
161
164
162
165
# Last resort, make the call to the server
163
166
options_uri = self ._combine_url (self .config .base_url , '_apis' )
@@ -184,7 +187,7 @@ def _get_resource_locations(self, all_host_types):
184
187
try :
185
188
OPTIONS_FILE_CACHE [self .normalized_url ] = wrapper .value
186
189
except SerializationError as ex :
187
- logging . exception ( str ( ex ) )
190
+ logger . debug ( ex , exc_info = True )
188
191
return returned_locations
189
192
190
193
@staticmethod
0 commit comments