35 lines
1.0 KiB
Python
35 lines
1.0 KiB
Python
import logging
|
|
import os
|
|
|
|
def buildLog (action, outputs, response):
|
|
if hasattr(action, "prints"):
|
|
try:
|
|
for print_name, print_key in action.prints.items():
|
|
print(
|
|
f"{print_name}:",
|
|
f"{outputs[print_key]}",
|
|
)
|
|
|
|
except (KeyError, TypeError):
|
|
pass
|
|
|
|
response_log = os.environ.get("LOGS_SUCCESS_RESPONSE", "false").lower() == "true"
|
|
|
|
if action.showstatus is True and response.ok:
|
|
if response_log:
|
|
print(f"{action.name} request successful with response {response.status_code}")
|
|
|
|
elif action.showstatus is True and not response.ok:
|
|
print(f"{action.name} failed with status code {response.status_code}")
|
|
|
|
try:
|
|
response_data = response.json()
|
|
except ValueError:
|
|
response_data = response.text
|
|
|
|
if isinstance(response_data, dict):
|
|
print("Response:", response_data.get("error", response_data))
|
|
else:
|
|
print("Response:", response_data)
|
|
return
|