Skip to content

Commit 4b5e068

Browse files
Merge branch 'feature/logging_augment' into development
2 parents b0db207 + 5c62e1b commit 4b5e068

1 file changed

Lines changed: 17 additions & 23 deletions

File tree

pyedgeconnect/__init__.py

Lines changed: 17 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -126,21 +126,22 @@ def _handle_response(
126126
:return: Requests Response object
127127
:rtype: requests.Response
128128
"""
129+
response_method = (
130+
str(response.request)
131+
.replace("<PreparedRequest ", "")
132+
.replace(">", "")
133+
)
129134
if response.status_code not in expected_status:
130135
self.logger.error(
131-
"{} {} | Received HTTP {} | Response text: {}".format(
132-
response.request,
133-
api_path,
134-
response.status_code,
135-
response.text,
136-
)
136+
f"{response_method} {api_path} | Received HTTP "
137+
f"{response.status_code} | Response text: {response.text}"
137138
)
138139
# return formatted data for the source method
139140
# for JSON data, return a dictionary with the details of
140141
# the response
141142
if return_type == "json":
142143
return {
143-
"request": response.request,
144+
"request": response_method,
144145
"api_path": api_path,
145146
"status_code": response.status_code,
146147
"text": response.text,
@@ -157,23 +158,16 @@ def _handle_response(
157158
# text from log messages for successful API calls.
158159
if self.log_success:
159160
self.logger.info(
160-
"{} {} | Received HTTP {} | Response text: {}".format(
161-
response.request,
162-
api_path,
163-
response.status_code,
164-
response.text,
165-
)
161+
f"{response_method} {api_path} | Received HTTP "
162+
f"{response.status_code} | Response text: {response.text}"
166163
)
167164
else:
168165
# Log successful call, omit response text in case sensitive
169166
# data in response text
170167
self.logger.info(
171-
(
172-
"{} {} | Received: HTTP {} ".format(
173-
response.request, api_path, response.status_code
174-
)
175-
+ "| Response text omitted to avoid logging sensitive data"
176-
)
168+
f"{response_method} {api_path} | Received HTTP "
169+
f"{response.status_code} "
170+
"| Response omitted to avoid logging sensitive data"
177171
)
178172

179173
# return formatted data for the source method
@@ -463,9 +457,9 @@ def __init__(
463457
)
464458

465459
# Setup general log settings for messages and errors
466-
self.logger = logging.getLogger("orchestrator")
460+
self.logger = logging.getLogger(f"orch_{url}")
467461
self.formatter = logging.Formatter(
468-
"%(asctime)s - %(levelname)s - %(message)s"
462+
"%(asctime)s - %(name)s - %(levelname)s - %(message)s"
469463
)
470464
self.logger.setLevel(logging.INFO)
471465

@@ -1301,9 +1295,9 @@ def __init__(
13011295
)
13021296

13031297
# Setup general log settings for messages and errors
1304-
self.logger = logging.getLogger("edgeconnect")
1298+
self.logger = logging.getLogger(f"ecos_{url}")
13051299
self.formatter = logging.Formatter(
1306-
"%(asctime)s - %(levelname)s - %(message)s"
1300+
"%(asctime)s - %(name)s - %(levelname)s - %(message)s"
13071301
)
13081302
self.logger.setLevel(logging.INFO)
13091303

0 commit comments

Comments
 (0)