How to View Task Logs in Apache Airflow
To view task logs in Apache Airflow, use the
Airflow UI by navigating to the specific DAG run and clicking the task instance's log link. Alternatively, use the airflow tasks logs CLI command with the DAG ID, task ID, and execution date to see logs in the terminal.Syntax
There are two main ways to view task logs in Airflow: via the UI and via the CLI.
- UI: Navigate to the DAG, select the DAG run, then click on the task instance and choose
View Log. - CLI: Use the command
airflow tasks logs <dag_id> <task_id> <execution_date>.
Each part means:
dag_id: The unique identifier of your DAG.task_id: The specific task within the DAG.execution_date: The run date/time of the DAG in ISO format (e.g.,2023-06-01T00:00:00+00:00).
bash
airflow tasks logs <dag_id> <task_id> <execution_date>
Example
This example shows how to view logs for a task named extract_data in a DAG called data_pipeline for a run on June 1, 2023.
bash
airflow tasks logs data_pipeline extract_data 2023-06-01T00:00:00+00:00
Output
[2023-06-01 00:00:01,234] {taskinstance.py:876} INFO - Starting attempt 1 of 1
[2023-06-01 00:00:02,345] {bashoperator.py:123} INFO - Running command: echo 'Extracting data'
Extracting data
[2023-06-01 00:00:03,456] {taskinstance.py:1100} INFO - Task succeeded
Common Pitfalls
Common mistakes when viewing Airflow task logs include:
- Using the wrong
execution_dateformat or timezone, causing no logs to show. - Trying to view logs for a task that has not run yet.
- Not having proper permissions to access the Airflow UI or logs directory.
- Confusing DAG run dates with task instance dates.
Always verify the exact execution_date from the Airflow UI or CLI before running the logs command.
bash
Wrong: airflow tasks logs data_pipeline extract_data 2023-06-01 Right: airflow tasks logs data_pipeline extract_data 2023-06-01T00:00:00+00:00
Quick Reference
| Method | Command/Action | Description |
|---|---|---|
| UI | Navigate DAG > DAG Run > Task > View Log | View logs in browser with full details and timestamps. |
| CLI | airflow tasks logs | View logs directly in terminal for quick access. |
| Log Files | Check logs directory (default: ~/airflow/logs/) | Access raw log files stored on disk if needed. |
Key Takeaways
Use the Airflow UI to easily view task logs with a few clicks.
The CLI command requires exact DAG ID, task ID, and execution date in ISO format.
Check the execution date carefully to avoid missing logs.
Ensure you have permissions to access logs in UI or filesystem.
Logs are also stored on disk under the Airflow logs directory for manual inspection.