如何将自己的日志添加到自动生成的Apache Airflow日志中?任何打印语句都不会登录,所以我想知道如何添加我的日志,以便它也显示在用户界面上?
尝试将“hello world”写入气流日志(气流 1.10.3)。基于此处和此处介绍的 SO 解决方案,我应该能够import logging和logging.info('hello world')。这对我来说似乎不起作用。
import logging
from datetime import datetime, timedelta
from airflow import DAG
from airflow.operators.python_operator import PythonOperator
default_args = {
'owner': 'benten',
'depends_on_past': False,
'start_date': datetime(2019, 7, 25),
'email_on_failure': False,
'retries': 1,
'retry_delay': timedelta(minutes=1),
}
def logging_is_fun():
logging.debug("hellow world")
logging.info("hello world")
logging.critical("hello world")
return None
with DAG('fun_logs', schedule_interval='45 * * * *', default_args=default_args) as dag:
log_task = PythonOperator(python_callable=logging_is_fun, task_id='log_test_task')
Run Code Online (Sandbox Code Playgroud)
我手动触发了 dag,任务执行没有问题。但唉,当我检查日志时,我看到的是:
*** Reading local file: /home/ubuntu/airflow/logs/fun_logs/log_test_task/2019-08-31T19:22:49.653712+00:00/1.log
我惊人的“hello …