Audit logging for sensitive operations

2653
0

Audit logs provide accountability and forensic capabilities for sensitive operations like permission changes, data deletion, or financial transactions. I store audit events in a dedicated table with who performed the action, what changed, when it occurred, and the request context (IP, user agent). For data changes, I use paper_trail gem to track all versions of critical models automatically. Each audit entry includes a JSON payload with before/after states so I can reconstruct history or implement undo functionality. Audit logs are write-only and never deleted—I archive old entries to cold storage but retain them indefinitely for compliance. For GDPR, I pseudonymize user identifiers while maintaining the ability to reconstruct events.