import logging 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 if action.showstatus is True and response.ok: print(f"{action.name} successful") try: response_data = response.json() except ValueError: response_data = response.text print(response_data) 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