Overview
The redaction system automatically masks sensitive data in log entries to prevent accidental exposure of secrets, credentials, and personal information. Implementation:~/workspace/source/options.go:83-129
Quick Start
Common Sensitive Fields
From~/workspace/source/options.go:128:
Custom Redaction
From~/workspace/source/options.go:59:
Redactor Implementation
From~/workspace/source/options.go:83-113:
Common Sensitive Keys
From~/workspace/source/options.go:116-124:
WithCommonRedaction() option masks all these fields automatically.
How Redaction Works
From~/workspace/source/logger_impl.go:186-189:
- Log entry is created with fields
- Caller info captured (if enabled)
- Stack trace captured (if enabled)
- Redactor scans all fields and masks sensitive ones
- Hooks execute
- Entry formatted and written
- Hooks receive redacted data (preventing leaks to Slack, etc.)
- Formatters write redacted values to files
- Original sensitive data never persists
Configuration Options
WithRedactor
From~/workspace/source/options.go:59:
WithCommonRedaction
From~/workspace/source/options.go:128:
Combining Custom and Common
WithRedactor call is applied. To combine, create a custom list:
Examples
Redacting Authentication Data
Redacting API Keys
Redacting Payment Information
Redacting in Child Loggers
Field Name Matching
Redaction is case-sensitive and matches exact field names:Mask Value
From~/workspace/source/options.go:96-97:
All redacted fields are replaced with "***".
The mask value is currently fixed. To customize:
Performance Impact
From~/workspace/source/options.go:103-112:
- O(n) where n = number of fields
- No allocations for non-redacted fields
- Fast map lookup for sensitive key detection
- Negligible overhead (~10-50ns per field)
Security Best Practices
Always Enable in Production
Redact Before Hooks
Redaction occurs before hooks execute (from~/workspace/source/logger_impl.go:186-197):
- Slack notifications
- Metrics systems
- External logging services
- Custom hooks
Review Common Keys
Periodically reviewCommonSensitiveKeys() to ensure it covers your use case:
Avoid Logging Secrets Entirely
Redaction is a safety net, not a primary defense:Testing Redaction
Limitations
Message Content Not Redacted
Redaction only applies to structured fields, not the message:Nested Structures
Redaction doesn’t traverse nested structures inAny() fields:
See Also
- Hooks - Redaction happens before hooks execute
- Security Guide - Comprehensive security practices
- Fields - Structured logging with type-safe fields