我正在使用 Apache Airflow 1.10.9(基于 puckel/docker-airflow
docker 镜像)通过 BashOperator
在 DAG 中运行多个 Python 脚本。日志当前写入 /usr/local/airflow/logs
。
是否可以将 Airflow 配置为
- 还将日志写入另一个目录,例如
/home/foo/logs
- 日志应仅包含 python 脚本的标准输出
日志应存储在以下目录/文件名格式中:
/home/foo/logs/[execution-date]-[dag-id]-[task-id].log
如果可能,重试应附加到同一
.log
文件中。否则,我们可以采用命名约定:/home/foo/logs/[execution-date]-[dag-id]-[task-id]-[retry-number].log
谢谢大家!
DAG 示例
from airflow import DAG
from airflow.operators.bash_operator import BashOperator
default_args = { ... }
dag = DAG(
'mydag',
default_args=default_args,
schedule_interval='*/10 * * * *',
)
# Log to /home/foo/logs/2020-05-12-mydag-hello_world.log
t1 = BashOperator(
task_id='hello_world',
bash_command='/path/to/env/bin/python /path/to/scripts/hello_world.py',
dag=dag,
)
# Log to /home/foo/logs/2020-05-12-mydag-hey_there.log
t2 = BashOperator(
task_id='hey_there',
bash_command='/path/to/env/bin/python /path/to/scripts/hey_there.py',
dag=dag,
)
t1 >> t2
最佳答案
https://bcb.github.io/airflow/run-dag-and-watch-logs
此链接有答案。
设置 FILENAME_TEMPLATE 设置。
导出 AIRFLOW__CORE__LOG_FILENAME_TEMPLATE="{{ ti.dag_id }}.log"
或
您可以编辑airflow.cfg文件 log_filename_template 变量
在那里添加任何与 Airflow 相关的变量。
关于python - 使用自定义文件名进行 Airflow 记录?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61757827/