Log Management System
Design and implement comprehensive log management systems including rotation, retention policies, log forwarding, aggregation, storage strategies, and lifecycle management for scalable observability.
When to use me
Use this skill when:
- Designing log management infrastructure for applications or services
- Implementing log rotation and retention policies
- Setting up log forwarding to centralized aggregation systems
- Planning log storage strategies for cost and performance optimization
- Establishing log lifecycle management (ingestion, processing, storage, archival, deletion)
- Troubleshooting log pipeline issues or performance problems
- Scaling log management for high-volume applications
- Ensuring compliance with data retention requirements
What I do
1. Log Rotation & Retention
- Design rotation policies based on size, time, or both
- Implement retention strategies (time-based, size-based, event-based)
- Configure compression for rotated logs (gzip, zstd, lz4)
- Establish archival procedures for long-term storage
- Implement deletion policies for expired logs
- Monitor rotation health and alert on failures
2. Log Forwarding & Aggregation
- Design forwarding architecture (agent-based, daemon-based, library-based)
- Implement reliable delivery with retries and backoff
- Configure batching and buffering for efficiency
- Handle network failures and connection issues
- Implement load balancing across aggregation endpoints
- Monitor forwarding latency and throughput
3. Log Storage Strategies
- Hot storage for recent logs (fast query, high cost)
- Warm storage for medium-term logs (balanced cost/performance)
- Cold storage for archival logs (slow query, low cost)
- Tiered storage with automatic data movement between tiers
- Compression optimization per storage tier
- Cost management across storage classes
4. Lifecycle Management
- Ingestion pipeline design and optimization
- Processing and enrichment at ingestion time
- Indexing strategies for efficient querying
- Retention enforcement across storage tiers
- Archival procedures to long-term storage
- Deletion processes for compliance requirements
5. Performance & Scaling
- Throughput optimization for high-volume logs
- Latency management for real-time requirements
- Resource utilization monitoring and optimization
- Scalability planning for growth
- Bottleneck identification and resolution
- Capacity planning for storage and processing
Log Rotation Patterns
Size-Based Rotation
/var/log/app/app.log
/var/log/app/app.log.1.gz
/var/log/app/app.log.2.gz
/var/log/app/app.log.3.gz
...
Configuration:
- Max file size: 100MB, 1GB, etc.
- Number of rotations: 10, 100, 1000
- Compression: On rotation, on creation
- Permissions: Maintain appropriate file permissions
Time-Based Rotation
/var/log/app/app-2026-02-26.log
/var/log/app/app-2026-02-25.log.gz
/var/log/app/app-2026-02-24.log.gz
...
Configuration:
- Rotation interval: Hourly, daily, weekly, monthly
- Retention period: 7 days, 30 days, 90 days, 1 year
- Timezone handling: UTC, local time, with offsets
- Naming conventions: Date-based, timestamp-based
Hybrid Rotation
- Primary rotation: Size-based for active file
- Secondary rotation: Time-based for archived files
- Tertiary compression: Compression after time period
- Quaternary archival: Move to cold storage after retention
Forwarding Architectures
Agent-Based Forwarding
Application → Local File → Log Agent (Fluentd/Logstash) → Central Aggregation
Advantages:
- Decouples application from forwarding logic
- Can buffer during network outages
- Can process/enrich before forwarding
- Supports multiple input/output formats
Disadvantages:
- Additional resource consumption
- Configuration management overhead
- Potential single point of failure
Library/Direct Forwarding
Application → Logging Library → Central Aggregation
Advantages:
- Simpler architecture
- Lower latency
- Fewer moving parts
Disadvantages:
- Coupled to application lifecycle
- Limited buffering during outages
- May lose logs during application crashes
Sidecar Pattern (Containers)
Application Container → Sidecar Container → Central Aggregation
Advantages:
- Decoupled but co-located
- Shares container lifecycle
- Can use specialized sidecar images
Disadvantages:
- Additional container overhead
- Inter-container communication complexity
Storage Tier Strategy
Tier 1: Hot Storage (0-7 days)
- Purpose: Real-time debugging, recent issue investigation
- Characteristics: Fast query, full-text search, high availability
- Examples: Elasticsearch, Splunk, Cloud Logging
- Retention: 1-7 days typically
- Cost: Highest per GB
Tier 2: Warm Storage (8-30 days)
- Purpose: Trend analysis, weekly/monthly reporting
- Characteristics: Slower query, aggregated views, good availability
- Examples: Compressed files on fast storage, warmed indices
- Retention: 8-30 days typically
- Cost: Medium per GB
Tier 3: Cold Storage (31-365 days)
- Purpose: Compliance, occasional investigations, historical analysis
- Characteristics: Very slow query, batch processing, lower availability
- Examples: Object storage (S3, GCS), tape backup
- Retention: 31-365+ days
- Cost: Lowest per GB
Tier 4: Archival Storage (1+ years)
- Purpose: Legal requirements, historical records
- Characteristics: Extremely slow retrieval, write-once-read-rarely
- Examples: Glacier, deep archival services
- Retention: Years to decades
- Cost: Minimal but retrieval costs may apply
Examples
# Configure log rotation policy
npm run log-management:configure-rotation -- --max-size 100MB --keep-files 10 --compress gzip
# Set up log forwarding
npm run log-management:configure-forwarding -- --agent fluentd --destination elasticsearch --batch-size 1000
# Design storage strategy
npm run log-management:design-storage -- --hot-days 7 --warm-days 30 --cold-days 365 --archive-years 7
# Analyze current log management
npm run log-management:analyze -- --path /var/log --output analysis.json
# Implement lifecycle policy
npm run log-management:lifecycle -- --ingestion-kafka --processing-flink --storage-s3 --retention-90d
Output format
Log Management Configuration:
log_management:
rotation:
strategy: "size_and_time"
max_size_mb: 100
max_age_days: 7
compress_on_rotation: true
compression_algorithm: "gzip"
keep_rotated: 10
forwarding:
method: "agent_based"
agent: "fluentd"
configuration:
buffer:
type: "file"
path: "/var/log/fluentd-buffer"
flush_interval: 5
retry_limit: 10
destination:
type: "elasticsearch"
hosts: ["elasticsearch:9200"]
index: "app-logs-%Y.%m.%d"
storage:
tiers:
hot:
type: "elasticsearch"
retention_days: 7
replication: 2
warm:
type: "s3"
retention_days: 30
compression: "zstd"
cold:
type: "glacier"
retention_days: 365
retrieval_time: "3-5 hours"
lifecycle:
ingestion_rate_limit: "10000/s"
processing_enrichment: true
indexing_strategy: "daily_index"
retention_enforcement: "automated"
archival_schedule: "daily"
deletion_procedure: "secure_delete"
monitoring:
metrics:
- log_volume_per_second
- rotation_success_rate
- forwarding_latency
- storage_utilization
alerts:
- rotation_failed
- forwarding_stopped
- storage_90_percent_full
- retention_violation
Log Management Assessment:
Log Management System Assessment
───────────────────────────────
System: payment-platform
Assessment Date: 2026-02-26
Score: 65/100
Current State:
✅ Log rotation implemented (size-based, 100MB)
✅ Basic forwarding to centralized system
✅ Hot storage configured (7 days retention)
Areas for Improvement:
⚠️ No tiered storage strategy (all logs in hot storage)
⚠️ Limited buffering during network outages (lose logs after 100MB)
⚠️ No lifecycle management (manual archival/deletion)
⚠️ No compression for rotated logs
⚠️ Inconsistent retention across services
Critical Issues:
❌ No monitoring of log management system itself
❌ Single point of failure in forwarding pipeline
❌ No disaster recovery for log data
❌ Compliance risks with retention policies
Storage Cost Analysis:
- Current: $2,500/month (all logs in hot storage)
- Optimized: $850/month (with tiered strategy)
- Savings potential: 66% with proper tiering
Recommendations:
1. Implement tiered storage strategy immediately
2. Add buffering and retry logic to forwarding
3. Automate lifecycle management
4. Set up comprehensive monitoring
5. Create disaster recovery plan for log data
Implementation Timeline:
- Week 1-2: Tiered storage implementation
- Week 3-4: Forwarding reliability improvements
- Week 5-6: Lifecycle automation
- Week 7-8: Monitoring and alerting
- Ongoing: Regular review and optimization
Notes
- Log management is not "set and forget" - requires ongoing maintenance
- Cost optimization is critical - log storage can become expensive quickly
- Reliability matters - lost logs mean lost observability
- Compliance requirements vary by industry and region
- Scalability planning should anticipate 10x-100x growth
- Disaster recovery for logs is often overlooked but critical
- Security considerations include access control and encryption
- Performance monitoring of the log management system itself is essential
- Regular review of policies and configurations as needs evolve
- Document everything - rotation policies, retention rules, procedures
1---2name: log-management-system3description: Implement comprehensive log management including rotation, retention, forwarding, aggregation, storage, and lifecycle management4license: MIT5---67# Log Management System89Design and implement comprehensive log management systems including rotation, retention policies, log forwarding, aggregation, storage strategies, and lifecycle management for scalable observability.1011## When to use me1213Use this skill when:14- Designing log management infrastructure for applications or services15- Implementing log rotation and retention policies16- Setting up log forwarding to centralized aggregation systems17- Planning log storage strategies for cost and performance optimization18- Establishing log lifecycle management (ingestion, processing, storage, archival, deletion)19- Troubleshooting log pipeline issues or performance problems20- Scaling log management for high-volume applications21- Ensuring compliance with data retention requirements2223## What I do2425### 1. Log Rotation & Retention26- **Design rotation policies** based on size, time, or both27- **Implement retention strategies** (time-based, size-based, event-based)28- **Configure compression** for rotated logs (gzip, zstd, lz4)29- **Establish archival procedures** for long-term storage30- **Implement deletion policies** for expired logs31- **Monitor rotation health** and alert on failures3233### 2. Log Forwarding & Aggregation34- **Design forwarding architecture** (agent-based, daemon-based, library-based)35- **Implement reliable delivery** with retries and backoff36- **Configure batching and buffering** for efficiency37- **Handle network failures** and connection issues38- **Implement load balancing** across aggregation endpoints39- **Monitor forwarding latency** and throughput4041### 3. Log Storage Strategies42- **Hot storage** for recent logs (fast query, high cost)43- **Warm storage** for medium-term logs (balanced cost/performance)44- **Cold storage** for archival logs (slow query, low cost)45- **Tiered storage** with automatic data movement between tiers46- **Compression optimization** per storage tier47- **Cost management** across storage classes4849### 4. Lifecycle Management50- **Ingestion pipeline** design and optimization51- **Processing and enrichment** at ingestion time52- **Indexing strategies** for efficient querying53- **Retention enforcement** across storage tiers54- **Archival procedures** to long-term storage55- **Deletion processes** for compliance requirements5657### 5. Performance & Scaling58- **Throughput optimization** for high-volume logs59- **Latency management** for real-time requirements60- **Resource utilization** monitoring and optimization61- **Scalability planning** for growth62- **Bottleneck identification** and resolution63- **Capacity planning** for storage and processing6465## Log Rotation Patterns6667### Size-Based Rotation68```69/var/log/app/app.log70/var/log/app/app.log.1.gz71/var/log/app/app.log.2.gz72/var/log/app/app.log.3.gz73...74```7576Configuration:77- **Max file size**: 100MB, 1GB, etc.78- **Number of rotations**: 10, 100, 100079- **Compression**: On rotation, on creation80- **Permissions**: Maintain appropriate file permissions8182### Time-Based Rotation83```84/var/log/app/app-2026-02-26.log85/var/log/app/app-2026-02-25.log.gz86/var/log/app/app-2026-02-24.log.gz87...88```8990Configuration:91- **Rotation interval**: Hourly, daily, weekly, monthly92- **Retention period**: 7 days, 30 days, 90 days, 1 year93- **Timezone handling**: UTC, local time, with offsets94- **Naming conventions**: Date-based, timestamp-based9596### Hybrid Rotation97- **Primary rotation**: Size-based for active file98- **Secondary rotation**: Time-based for archived files99- **Tertiary compression**: Compression after time period100- **Quaternary archival**: Move to cold storage after retention101102## Forwarding Architectures103104### Agent-Based Forwarding105```106Application → Local File → Log Agent (Fluentd/Logstash) → Central Aggregation107```108109**Advantages**:110- Decouples application from forwarding logic111- Can buffer during network outages112- Can process/enrich before forwarding113- Supports multiple input/output formats114115**Disadvantages**:116- Additional resource consumption117- Configuration management overhead118- Potential single point of failure119120### Library/Direct Forwarding121```122Application → Logging Library → Central Aggregation123```124125**Advantages**:126- Simpler architecture127- Lower latency128- Fewer moving parts129130**Disadvantages**:131- Coupled to application lifecycle132- Limited buffering during outages133- May lose logs during application crashes134135### Sidecar Pattern (Containers)136```137Application Container → Sidecar Container → Central Aggregation138```139140**Advantages**:141- Decoupled but co-located142- Shares container lifecycle143- Can use specialized sidecar images144145**Disadvantages**:146- Additional container overhead147- Inter-container communication complexity148149## Storage Tier Strategy150151### Tier 1: Hot Storage (0-7 days)152- **Purpose**: Real-time debugging, recent issue investigation153- **Characteristics**: Fast query, full-text search, high availability154- **Examples**: Elasticsearch, Splunk, Cloud Logging155- **Retention**: 1-7 days typically156- **Cost**: Highest per GB157158### Tier 2: Warm Storage (8-30 days)159- **Purpose**: Trend analysis, weekly/monthly reporting160- **Characteristics**: Slower query, aggregated views, good availability161- **Examples**: Compressed files on fast storage, warmed indices162- **Retention**: 8-30 days typically163- **Cost**: Medium per GB164165### Tier 3: Cold Storage (31-365 days)166- **Purpose**: Compliance, occasional investigations, historical analysis167- **Characteristics**: Very slow query, batch processing, lower availability168- **Examples**: Object storage (S3, GCS), tape backup169- **Retention**: 31-365+ days170- **Cost**: Lowest per GB171172### Tier 4: Archival Storage (1+ years)173- **Purpose**: Legal requirements, historical records174- **Characteristics**: Extremely slow retrieval, write-once-read-rarely175- **Examples**: Glacier, deep archival services176- **Retention**: Years to decades177- **Cost**: Minimal but retrieval costs may apply178179## Examples180181```bash182# Configure log rotation policy183npm run log-management:configure-rotation -- --max-size 100MB --keep-files 10 --compress gzip184185# Set up log forwarding186npm run log-management:configure-forwarding -- --agent fluentd --destination elasticsearch --batch-size 1000187188# Design storage strategy189npm run log-management:design-storage -- --hot-days 7 --warm-days 30 --cold-days 365 --archive-years 7190191# Analyze current log management192npm run log-management:analyze -- --path /var/log --output analysis.json193194# Implement lifecycle policy195npm run log-management:lifecycle -- --ingestion-kafka --processing-flink --storage-s3 --retention-90d196```197198## Output format199200### Log Management Configuration:201```yaml202log_management:203 rotation:204 strategy: "size_and_time"205 max_size_mb: 100206 max_age_days: 7207 compress_on_rotation: true208 compression_algorithm: "gzip"209 keep_rotated: 10210 211 forwarding:212 method: "agent_based"213 agent: "fluentd"214 configuration:215 buffer:216 type: "file"217 path: "/var/log/fluentd-buffer"218 flush_interval: 5219 retry_limit: 10220 destination:221 type: "elasticsearch"222 hosts: ["elasticsearch:9200"]223 index: "app-logs-%Y.%m.%d"224 225 storage:226 tiers:227 hot:228 type: "elasticsearch"229 retention_days: 7230 replication: 2231 warm:232 type: "s3"233 retention_days: 30234 compression: "zstd"235 cold:236 type: "glacier"237 retention_days: 365238 retrieval_time: "3-5 hours"239 240 lifecycle:241 ingestion_rate_limit: "10000/s"242 processing_enrichment: true243 indexing_strategy: "daily_index"244 retention_enforcement: "automated"245 archival_schedule: "daily"246 deletion_procedure: "secure_delete"247 248 monitoring:249 metrics:250 - log_volume_per_second251 - rotation_success_rate252 - forwarding_latency253 - storage_utilization254 alerts:255 - rotation_failed256 - forwarding_stopped257 - storage_90_percent_full258 - retention_violation259```260261### Log Management Assessment:262```263Log Management System Assessment264───────────────────────────────265System: payment-platform266Assessment Date: 2026-02-26267Score: 65/100268269Current State:270✅ Log rotation implemented (size-based, 100MB)271✅ Basic forwarding to centralized system272✅ Hot storage configured (7 days retention)273274Areas for Improvement:275⚠️ No tiered storage strategy (all logs in hot storage)276⚠️ Limited buffering during network outages (lose logs after 100MB)277⚠️ No lifecycle management (manual archival/deletion)278⚠️ No compression for rotated logs279⚠️ Inconsistent retention across services280281Critical Issues:282❌ No monitoring of log management system itself283❌ Single point of failure in forwarding pipeline284❌ No disaster recovery for log data285❌ Compliance risks with retention policies286287Storage Cost Analysis:288- Current: $2,500/month (all logs in hot storage)289- Optimized: $850/month (with tiered strategy)290- Savings potential: 66% with proper tiering291292Recommendations:2931. Implement tiered storage strategy immediately2942. Add buffering and retry logic to forwarding2953. Automate lifecycle management2964. Set up comprehensive monitoring2975. Create disaster recovery plan for log data298299Implementation Timeline:300- Week 1-2: Tiered storage implementation301- Week 3-4: Forwarding reliability improvements302- Week 5-6: Lifecycle automation303- Week 7-8: Monitoring and alerting304- Ongoing: Regular review and optimization305```306307## Notes308309- **Log management is not "set and forget"** - requires ongoing maintenance310- **Cost optimization is critical** - log storage can become expensive quickly311- **Reliability matters** - lost logs mean lost observability312- **Compliance requirements** vary by industry and region313- **Scalability planning** should anticipate 10x-100x growth314- **Disaster recovery** for logs is often overlooked but critical315- **Security considerations** include access control and encryption316- **Performance monitoring** of the log management system itself is essential317- **Regular review** of policies and configurations as needs evolve318- **Document everything** - rotation policies, retention rules, procedures