关闭 Snowflake DB 日志记录,同时仍将日志级别保留为 DEBUG



是否可以禁用 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*/

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

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

以使其仅记录警告或更高级别。

我发现@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 代码。 为了将这些静音,我还必须将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

试试这个

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

最新更新