| 51 | |
| 52 | @wraps(func) |
| 53 | def wrapper(*args, **kwargs): |
| 54 | # Log entry point |
| 55 | if log_enabled: |
| 56 | logger.info(f"{request.path} {request.method}") |
| 57 | |
| 58 | # Call the actual route function |
| 59 | response = func(*args, **kwargs) |
| 60 | |
| 61 | from werkzeug.wrappers import Response |
| 62 | |
| 63 | # Log exit point, including response summary if possible |
| 64 | try: |
| 65 | if log_enabled: |
| 66 | if isinstance(response, Response) and response.direct_passthrough: |
| 67 | logger.debug(f"{request.path} {request.method} - Response: File response") |
| 68 | else: |
| 69 | response_summary = response.get_data(as_text=True) |
| 70 | if 'settings' in request.path: |
| 71 | response_summary = "*** Settings are not logged ***" |
| 72 | logger.debug(f"{request.path} {request.method} - Response: {response_summary}") |
| 73 | except Exception as e: |
| 74 | logger.exception(f"{request.path} {request.method} - {e})") |
| 75 | |
| 76 | return response |
| 77 | return wrapper |
| 78 | return decorator |