Silent mode for Python ODBC connector (pyodbc)

Viewed 98

I have previously used a direct connector to my database (Snowflake):

import snowflake.connector

conn = snowflake.connector.connect(
    user='my.address@company.com',
    password='my_password',
    account='my_account_1',
    warehouse='MY_WAREHOUSE',
    role='my_role'
    )

With the Snowflake connector, when establishing the connection, the connection was silent, i.e. didn't print anything in the console.

I recently changed to using pyodbc, and downloaded, installed and configured the driver. Now my connection method is roughly:

import pyodbc
sconnect = "Provider=MSDASQL.1;DSN=Snowflake" # UID, PWD, server etc. in driver configuration

conn = pyodbc.connect(sconnect)
conn.setencoding(encoding='utf-8')
conn.setdecoding(pyodbc.SQL_CHAR, encoding='utf-8')

The connection works almost identically with the Snowflake connector, except for this slight annoyance...

2022-05-06T06:30:27.163 INFO  8169 Snowflake::Client::IFileTransferAgent.cpp::: External logger injected. libsnowflakeclient version: 0.2.3
May 06 09:30:27 INFO  8204 Driver::LogVersions: SDK Version: 10.00.05.1021
May 06 09:30:27 INFO  8204 Driver::LogVersions: DSII Version: 2.17.6
May 06 09:30:27 INFO  8204 Driver::Initialize: Database CHAR Encoding: UTF-8
May 06 09:30:27 INFO  8204 Driver::Initialize: Database WCHAR Encoding: UTF-16LE
May 06 09:30:27 INFO  8204 Driver::Initialize: ANSI CHAR Encoding: ibm-5348
May 06 09:30:27 INFO  8204 Driver::Initialize: Driver Manager WCHAR Encoding: UTF-16LE
...

Row upon row of info logs which I don't really need/want to see. It also prints all the queries I perform. This tends to make the following of the intended flow of the algorithm rather annoying.

Is there a 'silent mode' parameter for the pyodbc connection? I tried setting the "tracing" to 0 in the driver configuration, but that didn't seem to work. I also tried trudging through the pyodbc documentation but found no mention about disabling info prints.

1 Answers

There are 2 locations at which logging level is set:

  1. "LogLevel" within the ODBC driver registry entries - by default this is set to 4 (Info).

See here: https://community.snowflake.com/s/article/How-to-generate-log-file-on-Snowflake-connectors#ODBC

https://community.snowflake.com/s/article/How-to-generate-log-file-on-Snowflake-connectors#ODBC

  1. "Tracing" within the ODBC connection configuration

See here: https://docs.snowflake.com/en/user-guide/odbc-parameters.html#optional-connection-parameters

Setting both of these to level 2 (Error) or lower removes the messages for me.

Related