Advanced Logging

Fine-tune your logs with levels, truncation controls, and custom messages.

Privacy & Data Control

For sensitive endpoints, you might want to disable argument or result logging to prevent leaking PII.

routes/auth.py
# Privacy-Focused (No data logging)
# Logs: [CALL] sensitive_op / [RETURN] sensitive_op
@log(include_args=False, include_result=False)
async def sensitive_op(password: str): ...

Heavy Payloads

Prevent log flooding by setting a maximum length for logged arguments and results.

routes/files.py
# Debugging Heavy Payloads
# Truncates to 5000 chars, uses DEBUG level
@log(level="debug", max_length=5000, message="PAYLOAD_DEBUG")
async def process_large_file(file: bytes): ...

Detailed Signature

def log(
    func=None, *, 
    level: str = "info", 
    include_args: bool = True, 
    include_result: bool = True, 
    max_length: int = 200, 
    message: str = None
)
  • level: Logging level ("debug", "info", "warning", "error"). Default: "info".
  • include_args: If True, logs function arguments on entry. Default: True.
  • include_result: If True, logs return value on exit. Default: True.
  • max_length: Truncates arguments and results to this length. Default: 200.
  • message: Optional prefix tag for the log entry.