gpt-4.1-mini-2025-04-14· OpenAI
LMArena Human Preference 140K
Right, but I don't need to use the logging module, it could just write to a .log file…
- User
Right, but I don't need to use the logging module, it could just write to a .log file within the ffunction after the print statement as well
- Assistant
Got it! If you want a quick and simple solution without messing with the logging module, you can just append the success message directly to a separate log file inside your function.
Here’s how you can do it:
def update_network(network_ref, updates): """ Update a network in Infoblox. """ endpoint = f"{BASE_URL}/{network_ref}" try: response = requests.put( endpoint, json=updates, auth=HTTPBasicAuth(USERNAME, PASSWORD), verify=False ) if response.status_code == 200: success_message = f"Network {network_ref} updated successfully. Response: {response.json()}\n" print(f"Network updated successfully: {response.json()}") # Append success message to a separate log file with open("successful_network_updates.log", "a") as f: f.write(success_message) else: print(f"Update error: {response.status_code} - {response.text}") except requests.exceptions.RequestException as e: print(f"Update request failed: {e}")