气流复制日志

  • 本文关键字:日志 复制 airflow
  • 更新时间 :
  • 英文 :


我正在使用 Airflow 1.10.4,当我在自定义模块中使用日志记录时遇到问题。

我的代码是这样的:

import logging
log = logging.getLogger(__name__)
log.info('hello there')

输出如下所示:

[2020-01-22 09:44:29,954] {{logging_mixin.py:95}} INFO - [[34m2020-01-22 09:44:29,954[0m] {{[34mbase_hook.py:[0m84}} INFO[0m - hello there.

时间、文件名和日志记录级别在我的日志的每一行中都是重复的。 如何实现气流日志以避免这种情况?(我在运算符中使用了 self.log,没有问题。

检查airflow.cfg文件中的log_format值。

我的默认配置:

# Log format
log_format = [%%(asctime)s] {%%(filename)s:%%(lineno)d} %%(levelname)s - %%(message)s
simple_log_format = %%(asctime)s %%(levelname)s - %%(message)s

由于Airflow的默认日志记录格式是[%%(asctime)s] {%%(filename)s:%%(lineno)d} %%(levelname)s - %%(message)s,日志中将始终有重复项,因为例如日期时间一次显示在asctime中,一次显示在message本身中。因此,为了解决这个问题,您需要更改气流的日志记录格式以仅显示message

如果您使用的是docker-compose.yaml则需要像这样设置它:

AIRFLOW__LOGGING__LOG_FORMAT: '%(message)s'

否则,您必须按照@AliNadi提到的airflow.cfg设置它:

log_format = %%(message)s

注意:我有一个额外的问题 - 对我来说,message也被复制了。原因是在python代码中,我调用了logging.basicConfig(),然后像这样logger = logging.getLogger(__name__)另外配置了记录器,logger.setLevel(logging.DEBUG)...解决方案是删除logging.basicConfig()并保留我的自定义日志记录配置。

参考:这里

最新更新