简体   繁体   English

有谁知道如何抑制所有气流“信息”级日志,但不抑制特定于应用程序实施的日志?

[英]Does anyone know how to suppress all airflow “info” level logs, but not suppress application implementation specific logs?

Airflow 1.10.1 has an attribute called "logging_level" that I believe is tied to the Python logging level. Airflow 1.10.1具有一个称为“ logging_level”的属性,我相信它与Python日志记录级别有关。 When the value is INFO or lower, the output logs are too verbose and unnecessary in deployments. 当该值为INFO或更低时,输出日志太冗长且在部署中不必要。

Rather, I want to be able to log just airflow framework errors, and everything I want my application to log. 相反,我希望能够仅记录气流框架错误以及我希望我的应用程序记录的所有内容。 Then I cut down on the logging to something minimal, most just in the context of the application, and only keep airflow framework/execution errors. 然后,我将日志记录减少到最少,主要是在应用程序的上下文中,并且仅保留气流框架/执行错误。

In a particular PythonOperator I wrote at 5 different levels of log to see what happens to them when I modify the airflow.cfg logging_level. 在一个特定的PythonOperator中,我写了5个不同级别的日志,以查看修改airflow.cfg logging_level时它们发生了什么。

 logging.debug('******************* HELLO debug *******************') logging.info('******************* HELLO info *******************') logging.warning('******************* HELLO warning *******************') logging.error('******************* HELLO error *******************') logging.critical('******************* HELLO critical *******************') 

The idea being that by changing the airflow.cfg attribute for logging_level from debug to info to warning, I can see less and less of the airflow logs, and just leave the application specific logs I want. 想法是,通过将logging_level的airflow.cfg属性从debug更改为info到warning,可以看到越来越少的气流日志,而只留下我想要的应用程序特定日志。

Step 1: logging_level = DEBUG 步骤1:logging_level =调试

Here's the log from the task that has logs at all level from debug upward. 这是任务的日志,该日志具有从调试到向上的所有级别的日志。

在此处输入图片说明

Step 2: logging_level = INFO 步骤2:logging_level = INFO

As expected, the logs do not include debug level messages. 符合预期,日志不包含调试级别消息。 在此处输入图片说明

Step 3: logging_level = WARNING 步骤3:logging_level =警告

When we go up from INFO to WARNING, the file is empty. 当我们从INFO转到WARNING时,该文件为空。 I was expecting the warning, error, and critical messages in the file and the rest suppressed from Airflow since the log did not contain anything from airflow at the level above INFO. 我期待文件中的警告,错误和严重消息,而其余消息则不受气流限制,因为日志中不包含高于INFO级别的气流消息。

在此处输入图片说明

Step 4: logging_level = ERROR 步骤4:logging_level =错误

The same problem here again, the file is empty. 再次出现相同的问题,文件为空。 I expected to get the error and critical messages, but the file is empty. 我预计会收到错误和严重消息,但文件为空。

在此处输入图片说明

Note, in the last two screenshots, it's not that the path is invalid, but Airflow just displays the path to the file it seems in the absence of any content in the log file. 请注意,在最后两个屏幕截图中,并不是路径无效,而是Airflow仅显示文件路径,似乎日志文件中没有任何内容。

So my question is: 1) Is this just an Airflow bug? 所以我的问题是:1)这仅仅是一个气流错误吗? 2) Am I not using this properly? 2)我使用不正确吗? Or do I need to do something else in order to suppress Airflow level logs from INFO and below in production, and just keep my application specific logs? 还是为了抑制生产中INFO及以下版本的气流水平日志,而只保留我的应用程序特定日志,我是否需要做其他事情?

If you notice in your log screenshots your log message are actually wrapped in an info log. 如果您在日志屏幕截图中注意到,则您的日志消息实际上被包装在信息日志中。 If you want to actually change the log level within the task log and not wrap it you can pull the log off of the task instance (from the **kwargs) and use it directly as opposed to generically calling logging.warning(). 如果您想实际更改任务日志中的日志级别而不包装它,则可以从任务实例中拉出日志(从** kwargs中提取)并直接使用它,而不是一般地调用logging.warning()。 Here is an example: 这是一个例子:

def your_python_callable(**kwargs):
    log = kwargs["ti"].log
    log.warning("******HELLO Debug******")

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM