Add Logging
Opened this issue · 1 comments
cyberphor commented
Issue
Add Logging
Discussion
Logging would make debugging easier.
Recommendation(s)
- Create a logging package and handler.
- Log all successful and attempted changes made to Azure-based resources.
- Use JSON.
- Use a configurable path for the logging destination.
RWayne93 commented
import logging
import os
# Configure logging
log_file_path = os.getenv('LOG_PATH', './vm_creation_logs.json')
logging.basicConfig(filename=log_file_path, level=logging.INFO,
format='{"time": "%(asctime)s", "level": "%(levelname)s", "message": "%(message)s"}')
class AzureVM:
def create_virtual_machine(self, resource_group_name, vm_name, admin_user, admin_password, ports=[], image_data=None, vm_size=None):
try:
logging.info(f"VM {vm_name} created with ID: {vm_info.id}")
except Exception as e:
logging.error(f"Failed to create VM {vm_name}. Error: {str(e)}")
For the VM i was thinking something like this maybe?