Skip to content

Commit 0562f8a

Browse files
committed
restoring logging_other files
1 parent 7ba4115 commit 0562f8a

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

mssql_python/connection.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
from mssql_python.cursor import Cursor
1616
from mssql_python.logging_config import get_logger
1717
from mssql_python.constants import ConstantsDDBC as ddbc_sql_const
18-
from mssql_python.helpers import add_driver_to_connection_str, check_error
18+
from mssql_python.helpers import add_driver_to_connection_str, sanitize_connection_string
1919
from mssql_python import ddbc_bindings
2020
from mssql_python.pooling import PoolingManager
2121
from mssql_python.exceptions import DatabaseError, InterfaceError
@@ -127,7 +127,7 @@ def _construct_connection_string(self, connection_str: str = "", **kwargs) -> st
127127
conn_str += f"{key}={value};"
128128

129129
if logger:
130-
logger.info("Final connection string: %s", conn_str)
130+
logger.info("Final connection string: %s", sanitize_connection_string(conn_str))
131131

132132
return conn_str
133133

mssql_python/helpers.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,3 +184,17 @@ def get_driver_path(module_dir, architecture):
184184
raise RuntimeError(f"ODBC driver not found at: {driver_path_str}")
185185

186186
return driver_path_str
187+
188+
189+
def sanitize_connection_string(conn_str: str) -> str:
190+
"""
191+
Sanitize the connection string by removing sensitive information.
192+
Args:
193+
conn_str (str): The connection string to sanitize.
194+
Returns:
195+
str: The sanitized connection string.
196+
"""
197+
# Remove sensitive information from the connection string, Pwd section
198+
# Replace Pwd=...; or Pwd=... (end of string) with Pwd=***;
199+
import re
200+
return re.sub(r"(Pwd\s*=\s*)[^;]*", r"\1***", conn_str, flags=re.IGNORECASE)

0 commit comments

Comments
 (0)