【问题标题】:Where to check logs of webserver_config.py in Airflow?在 Airflow 中哪里可以查看 webserver_config.py 的日志?
【发布时间】:2022-08-17 20:57:35
【问题描述】:
  import os
  import logging
  from flask.appbuilder.security.manager import AUTH_OAUTH
  from airflow.www.security import AirflowSecurityManager
  
  AUTH_TYPE = AUTH_OAUTH
  AUTH_ROLES_SYNC_AT_LOGIN = True
  AUTH_USER_REGISTRATION = True
  
  log = logging.getLogger(__name__)
  log.setLevel(os.getenv(\"AIRFLOW__LOGGING__FAB_LOGGING_LEVEL\", \"INFO\"))
  
  OAUTH_PROVIDERS = [
      {
          \"name\": \"egast\",
          \"icon\": \"fa-address-card\",
          \"token_key\": \"access_token\",
          \"remote_app\": {
              \"client_id\": \"<id>\",
              \"client_secret\": \"<secret>\",
              \"client_kwargs\": {
                  \"scope\": \"<scope>\",
                  \"grant_type\": \"authorization_code\",
              },
              \"access_token_method\": \"POST\",
              \"access_token_params\": {
                  \"client_id\": \"<id>\",
              },
              \"request_token_url\": None,
              \"api_base_url\": \"<url>\",
              \"access_token_url\": \"<url>/token.oauth2\",
              \"authorize_url\": \"<url>/authorization.oauth2\"
          }
      }
  ]
  
  class CustomSecurityManager(AirflowSecurityManager):
  
      def oauth_user_info(sm, provider, response=None):
          if provider == \"egast\":
              me = sm.oauth_remote[provider].get(\"userinfo\")
              log.debug(me.data)
              logging.info(me.data)
              logging.debug(me.data)
              print(me.data)
          else:
              log.debug(\"Nothing!!\")
              logging.info(\"Nothing!!\")
              logging.debug(\"Nothing!!\")
              print(\"Nothing!!\")
  
  
  SECURITY_MANAGER_CLASS = CustomSecurityManager
  AUTH_ROLES_MAPPING = {
      \"FAB_USERS\": [\'User\'],
      \"FAB_ADMINS\": [\'Admin\']
  }

我正在尝试将 oauth 集成到 Airflow 中,并且我有一个 CustomSecurityManager 类,我正在其中打印或记录一些要调试的语句。在 /home/airflow/airflow/ 下生成了几个日志文件,例如 airflow.cfg、webserver.log、webserver.out、scheduler.log 等。但它们都不包含这些 webserver_config.py 日志。那么,启动 Airflow 网络服务器和调度程序后,我究竟在哪里可以找到这些日志?

    标签: python oauth-2.0 airflow


    【解决方案1】:

    您能否补充:以下内容:

      import logging
      from airflow.utils.log.logging_mixin import RedirectStdHandler
      
      logger = logging.getLogger(__name__)
      handler = RedirectStdHandler(stream='stdout')
      logger.addHandler(handler)
      logger.info("hello-world")
    

    与其他日志语句相比,日志格式已关闭,但我现在得到以下信息:

      ____________       _____________
     ____    |__( )_________  __/__  /________      __
    ____  /| |_  /__  ___/_  /_ __  /_  __ \_ | /| / /
    ___  ___ |  / _  /   _  __/ _  / / /_/ /_ |/ |/ /
     _/_/  |_/_/  /_/    /_/    /_/  \____/____/|__/
    [2022-08-17 12:40:22,554] {webserver_config.py:16} INFO - hello-world
    

    (我正在使用 Kubernetes 执行器设置,但我不认为这很重要)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-01-15
      • 1970-01-01
      • 2020-07-17
      • 2018-08-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多