import os from flask import current_app from datetime import datetime def log_activity(user, action, details=""): try: log_file = os.path.join(current_app.root_path, "activity.log") timestamp = datetime.now().strftime("%Y-%m-%d %H:%M:%S") with open(log_file, "a") as f: f.write( f"Timestamp: {timestamp} | User: {user} | " f"Action: {action} | Details: {details}\n" ) except Exception as e: print(f"Logging failed: {e}")