Airflow Logs & Log Retention Policies
From Debugging to Governance ππβ
The Story: When Something Breaks at 2 AMβ
A DAG fails at 2:03 AM.
The scheduler looks healthy.
The task retried twice.
The UI just says βFailedβ.
Now comes the only question that matters:
What actually happened?
That answer lives in Airflow logs.
Logs are not just debugging tools β they are:
- Your audit trail
- Your compliance evidence
- Your root-cause analysis system
In this article, weβll explain how Airflow logging works, where logs are stored, how retention works, and how to manage logs professionally at scale.
What Are Airflow Logs?β
Airflow logs capture everything that happens during task execution and system operation, including:
- Task start and end
- Errors and stack traces
- Retry attempts
- Environment details
- Operator-level output
- Scheduler and worker decisions
π Logs answer why something happened β metadata only answers what happened.
Types of Logs in Apache Airflowβ
Airflow generates multiple categories of logs, each serving a different purpose.
1οΈβ£ Task Logs (Most Important)β
Generated for every task execution.
Includes:
- Python
print()output - Exceptions and tracebacks
- Operator logs
- Retry information
π This is what you see when you click βView Logβ in the UI.
2οΈβ£ Scheduler Logsβ
Generated by the Scheduler process.
Captures:
- DAG parsing issues
- Scheduling delays
- Dependency resolution
- Heartbeat failures
π First place to check when DAGs donβt trigger.
3οΈβ£ Webserver Logsβ
Generated by the Airflow Web UI.
Captures:
- UI errors
- Authentication issues
- API requests
4οΈβ£ Worker Logsβ
Generated by Celery / Kubernetes / Local workers.
Captures:
- Task execution environment
- Resource failures
- Worker crashes
How Airflow Stores Logs (Architecture)β
By default, Airflow writes logs like this:
logs/
βββ dag_id=example_dag/
βββ task_id=extract_data/
βββ execution_date=2024-01-10/
βββ attempt=1.log
Each retry creates a new log file.
π This structure enables:
- Per-task isolation
- Retry-level visibility
- Easy debugging
Local Logging vs Remote Loggingβ
Local Logging (Default)β
Logs stored on:
- Scheduler disk
- Worker disk
β Problems:
- Logs disappear if workers restart
- Not scalable
- Not suitable for distributed systems
Remote Logging (Recommended)β
Logs stored in:
- Amazon S3
- Google Cloud Storage
- Azure Blob Storage
- Elasticsearch (advanced)
β Benefits:
- Centralized logs
- Durable storage
- Multi-worker support
- Compliance-friendly
π Remote logging is mandatory for production.
(Remote logging is covered deeply in the next article.)
Log Lifecycle: From Creation to Cleanupβ
Task Starts
β Log File Created
β Logs Written Incrementally
β Task Ends
β Log Archived (Optional)
β Log Retention Policy Applies
β Log Deleted
π Without retention policies, logs grow endlessly.
What Is Log Retention in Airflow?β
Log retention defines:
- How long logs are kept
- When old logs are deleted
- How storage costs are controlled
Retention applies to:
- Task logs
- Scheduler logs
- Worker logs
- Webserver logs
Why Log Retention Is Criticalβ
Without retention:
- Disk fills up
- Airflow crashes
- Cloud storage costs explode
- Compliance risks increase
With retention:
- Predictable storage usage
- Faster UI
- Cleaner debugging
- Compliance alignment
Log Retention Strategiesβ
Strategy 1: Time-Based Retention (Most Common)β
Example:
- Keep logs for 30 days
- Delete anything older
find airflow/logs -type f -mtime +30 -delete
π Works well for most teams.
Strategy 2: Compliance-Based Retentionβ
Example:
- Finance logs: 1 year
- PII-related logs: 90 days
- Dev logs: 14 days
π Often implemented using remote storage lifecycle rules.
Strategy 3: Size-Based Retentionβ
Example:
- Keep total logs under 500 GB
- Delete oldest first
π More complex, less common.
Log Retention with Remote Storage (Best Practice)β
If using S3 / GCS / Azure Blob, retention is usually handled by:
- Lifecycle policies
- Not Airflow itself
Example: S3 Lifecycle Rule (Conceptual)β
| Rule | Action |
|---|---|
| After 30 days | Move to Glacier |
| After 90 days | Delete |
π This is cheap, reliable, and scalable.
Input & Output Example (Realistic)β
Inputβ
- 100 DAGs
- Each DAG runs daily
- 20 tasks per DAG
- 2 retries
- Logs retained for 30 days
Outputβ
| Metric | Value |
|---|---|
| Log files/day | ~4,000 |
| Log files/month | ~120,000 |
| Storage required | ~50β100 GB |
π Without retention β unbounded growth.
Common Logging Mistakesβ
β Storing logs only locally
β Never cleaning old logs
β Logging sensitive secrets
β Excessive debug logging
β Ignoring worker disk limits
Logging Best Practices (Production-Grade)β
β
Enable remote logging
β
Apply storage lifecycle policies
β
Mask secrets in logs
β
Use INFO level by default
β
Monitor log storage growth
β
Separate system logs from task logs
Relationship to Metadata Databaseβ
| Logs | Metadata DB |
|---|---|
| Stores why something happened | Stores what happened |
| Large files | Structured rows |
| Stored in storage backend | Stored in relational DB |
| Retention-critical | Cleanup-critical |
π Both must be managed together.
Summary π§ β
- Airflow logs are the foundation of debugging and observability
- Task logs are the most valuable
- Local logging doesnβt scale
- Remote logging is production-standard
- Log retention prevents failures and cost explosions
- Storage lifecycle policies are the safest approach
Key Takeawaysβ
- β Logs explain failures β metadata does not
- β Remote logging is mandatory at scale
- β Retention policies protect stability and cost
- β Lifecycle rules outperform manual cleanup
- β Logging is part of governance, not just debugging
Whatβs Next? πβ
β‘οΈ Remote Logging in Airflow (S3, GCS, Azure Blob)
Deep dive into configuration, architecture, and real production setups