【问题标题】:Turning off Snowflake DB logging while still keeping log level as DEBUG关闭 Snowflake DB 日志记录,同时仍将日志级别保持为 DEBUG
【发布时间】:2019-10-24 18:58:55
【问题描述】:

是否可以禁用 Snowflake SQL 日志记录,该日志记录数据库连接的开始和结束以及正在执行的所有查询,同时保留 logging.basicConfig(level=logging.INFO) 以调试我的开发。

也许这不是 Snowflake 特有的,而是来自 Python 的一般数据库连接?

我正在使用snowflake-connector-python 1.8.1 版

我目前拥有的简化日志示例。

2019-06-10 16:27:10,015 INFO: /*Need this line*/

2019-06-10 16:27:10,015 INFO: Snowflake Connector for Python Version: 1.8.1, Python Version: 3.7.3, Platform: Windows-7-6.1.7601-SP1
2019-06-10 16:27:10,015 INFO: This connection is in OCSP Fail Open Mode. TLS Certificates would be checked for validity and revocation status. Any other Certificate Revocation related exceptions or OCSP Responder failures would be disregarded in favor of connectivity.
2019-06-10 16:27:10,020 INFO: Starting new HTTPS connection (1): xyz.snowflakecomputing.com
2019-06-10 16:27:11,227 INFO: query: [USE WAREHOUSE test_wh]
2019-06-10 16:27:11,481 INFO: query execution done
2019-06-10 16:27:11,481 INFO: query: [SELECT COLUMN_NAME FROM DB.INFORMATION_SCHEMA.COLUMNS WHERE TABLE_CATALOG =...]
2019-06-10 16:27:12,830 INFO: query execution done
2019-06-10 16:27:12,830 INFO: fetching data done
2019-06-10 16:27:12,830 INFO: closed
2019-06-10 16:27:13,185 INFO: /*Need this line*/
2019-06-10 16:27:13,581 INFO: /*Need this line*/
2019-06-10 16:27:14,604 INFO: /*Need this line*/

【问题讨论】:

    标签: python logging database-connection snowflake-cloud-data-platform


    【解决方案1】:

    在导入 snowflake.connector 的 Python 模块中,在调用连接器上的任何方法之前,添加

    logging.getLogger('snowflake.connector').setLevel(logging.WARNING)
    

    让它只记录警告或更高级别。

    【讨论】:

      【解决方案2】:

      我发现@john Velonis 的解决方案并没有完全摆脱所有雪花消息。我仍然收到这样的消息:

      2020-03-26 18:03:04    DEBUG:  network._request_exec:805 - SUCCESS
      2020-03-26 18:03:04    DEBUG:  network._use_requests_session:944 - Active requests sessions: 0, idle: 1
      2020-03-26 18:03:04    DEBUG:  network._post_request:533 - ret[code] = None, after post request
      2020-03-26 18:03:04    DEBUG:   cursor.execute:543 - sfqid: 0193261b-0310-8c37-0003-c9033ae3696a
      2020-03-26 18:03:04     INFO:   cursor.execute:545 - query execution done
      2020-03-26 18:03:04    DEBUG:   cursor.execute:547 - SUCCESS
      2020-03-26 18:03:04    DEBUG:   cursor.execute:551 - PUT OR GET: None
      2020-03-26 18:03:04    DEBUG:   cursor._init_result_and_meta:611 - Query result format: arrow
      2020-03-26 18:03:04    DEBUG:   cursor._init_result_and_meta:631 - Batches read: 8
      2020-03-26 18:03:04    DEBUG:   cursor.fetchone:824 - Arrow BatchSize: 8
      2020-03-26 18:03:04    DEBUG:   cursor.fetchone:824 - Arrow chunk info: batchCount 8, columnCount 8, use_numpy: 0
      2020-03-26 18:03:04    DEBUG:   cursor.fetchone:824 - Current batch index: 0, rows in current batch: 48
      2020-03-26 18:03:04    DEBUG:   cursor.fetchone:824 - Current batch index: 1, rows in current batch: 52
      2020-03-26 18:03:04    DEBUG:   cursor.fetchone:824 - Current batch index
      

      我认为这些来自CPP code here。要将这些也静音,我还必须将snowflake.connector.CArrowIterator 设置为更高的日志级别。我使用了这样的代码:

      import logging
      for name in logging.Logger.manager.loggerDict.keys():
          if 'snowflake' in name:
              logging.getLogger(name).setLevel(logging.WARNING)
              logging.getLogger(name).propagate = False
      

      【讨论】:

        【解决方案3】:

        试试这个

        logging.getLogger('snowflake.connector.connection').propagate=False
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2011-05-06
          • 2018-08-03
          • 2013-03-26
          • 2012-02-24
          • 2011-05-06
          相关资源
          最近更新 更多