# models/logging_config.py import os import logging def setup_logging(): log_dir = os.environ.get('LOG_DIR', '/app/logs') try: os.makedirs(log_dir, exist_ok=True) log_file = os.path.join(log_dir, 'app.log') # Ensure log file exists and is writable if not os.path.exists(log_file): open(log_file, 'a').close() os.chmod(log_file, 0o666) logging.basicConfig( level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s', handlers=[ logging.FileHandler(log_file), logging.StreamHandler() ] ) return logging.getLogger(__name__) except Exception as e: # Fallback to console-only logging if file logging fails logging.basicConfig( level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s', handlers=[logging.StreamHandler()] ) return logging.getLogger(__name__) logger = setup_logging()