Logging Configuration¶
FastAPI Guard provides detailed logging capabilities for security events.
Basic Logging Setup¶
Configure basic logging:
Log Levels¶
Configure different log levels:
Custom Logger¶
Use the logging utilities directly:
from guard.utils import setup_custom_logging, log_suspicious_activity
# Setup logger
logger = await setup_custom_logging("custom.log")
# Log suspicious activity
await log_suspicious_activity(
request,
"Suspicious pattern detected",
logger
)
Log Format¶
Default log format:
2024-01-20 10:15:23 - WARNING - Suspicious activity detected from 192.168.1.1: POST /api/data - Headers: {'User-Agent': 'curl/7.64.1'}
Request Logging¶
Log all incoming requests: