【问题标题】:Airflow Logging with Custom Filenames?带有自定义文件名的气流记录?
【发布时间】:2020-08-28 15:42:06
【问题描述】:

我正在使用 Apache Airflow 1.10.9(基于 puckel/docker-airflow docker 映像)通过 BashOperator 在 DAG 中运行多个 Python 脚本。日志当前写入/usr/local/airflow/logs

是否可以将 Airflow 配置为

  1. 将日志写入另一个目录,例如/home/foo/logs
  2. 日志应该只包含来自 python 脚本的标准输出
  3. 日志应按以下目录/文件名格式存储:

    /home/foo/logs/[execution-date]-[dag-id]-[task-id].log
    
  4. 如果可能,重试应附加到相同的.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

【问题讨论】:

    标签: python python-3.x logging airflow


    【解决方案1】:

    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 变量

    在那里添加任何与气流相关的变量。

    【讨论】:

      猜你喜欢
      • 2020-04-18
      • 2020-03-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-04-23
      • 1970-01-01
      • 1970-01-01
      • 2022-12-15
      相关资源
      最近更新 更多