You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
### ADO Work Item Reference
<!-- Insert your ADO Work Item ID below (e.g. AB#37452) -->
>
[AB#37336](https://sqlclientdrivers.visualstudio.com/c6d89619-62de-46a0-8b46-70b92a84d85e/_workitems/edit/37336)
-------------------------------------------------------------------
### Summary
<!-- Insert your Copilot Generated Summary below -->
This pull request refactors the logging system in the `mssql_python`
package, replacing the previous global logging mechanism with a
centralized `LoggingManager` class. It also introduces a universal
logging helper function (`log`) and a utility to sanitize sensitive
information in connection strings. Additionally, it simplifies the
codebase by removing redundant logging checks and improving resource
management for cursors and connections.
### Logging System Refactor:
* Introduced `LoggingManager` as a singleton class to manage logging
configuration, replacing the global `ENABLE_LOGGING` variable. The class
centralizes logging setup and provides backward compatibility for
checking if logging is enabled. (`mssql_python/logging_config.py`,
[mssql_python/logging_config.pyR11-R52](diffhunk://#diff-36f7c1765dd718a86de00178366ca7ab8e503766ca04b601e859d943d82a292dR11-R52))
* Added a universal `log` function in `helpers.py` to streamline logging
calls across the codebase. This function dynamically retrieves a logger
instance and supports multiple log levels. (`mssql_python/helpers.py`,
[mssql_python/helpers.pyR187-R214](diffhunk://#diff-7e002427036075c912554bb92d9e19681ea477e7c2a0eec56d284934d9125343R187-R214))
### Code Simplification:
* Replaced conditional `ENABLE_LOGGING` checks with calls to the new
`log` function, simplifying logging logic in `connection.py`,
`cursor.py`, and `exceptions.py`. (`mssql_python/connection.py`,
[[1]](diffhunk://#diff-29bb94de45aae51c23a6426d40133c28e4161e68769e08d046059c7186264e90L129-R125);
`mssql_python/cursor.py`,
[[2]](diffhunk://#diff-deceea46ae01082ce8400e14fa02f4b7585afb7b5ed9885338b66494f5f38280L465-R449);
`mssql_python/exceptions.py`,
[[3]](diffhunk://#diff-261e8fab7c29f0ba7f4dcdd1f977df5c9f02d3423c86cc935c3f617fd15c2d5fL644-R644)
* Removed redundant `logger` initialization from several modules, as the
`log` function now handles logger retrieval. (`mssql_python/auth.py`,
[[1]](diffhunk://#diff-19a0c93fc8573a5a7bfcadda0a2fb8f1b340c4502e1308c4f8a1e4508136c6e1L10-L14);
`mssql_python/cursor.py`,
[[2]](diffhunk://#diff-deceea46ae01082ce8400e14fa02f4b7585afb7b5ed9885338b66494f5f38280L17-L23)
### New Utilities:
* Added `sanitize_connection_string` in `helpers.py` to mask sensitive
information (e.g., passwords) in connection strings before logging.
(`mssql_python/helpers.py`,
[mssql_python/helpers.pyR187-R214](diffhunk://#diff-7e002427036075c912554bb92d9e19681ea477e7c2a0eec56d284934d9125343R187-R214))
### Resource Management Improvements:
* Improved cursor tracking by explicitly adding cursors to a
connection's cursor set and ensuring proper cleanup during resource
deallocation. (`mssql_python/connection.py`,
[mssql_python/connection.pyR186](diffhunk://#diff-29bb94de45aae51c23a6426d40133c28e4161e68769e08d046059c7186264e90R186))
* Refactored cursor cleanup logic to avoid unnecessary operations and
ensure weak references are handled correctly. (`mssql_python/cursor.py`,
[mssql_python/cursor.pyL419-R432](diffhunk://#diff-deceea46ae01082ce8400e14fa02f4b7585afb7b5ed9885338b66494f5f38280L419-R432))
### Minor Enhancements:
* Updated `__del__` methods in `connection.py` and `cursor.py` to handle
exceptions gracefully during cleanup, avoiding issues during garbage
collection. (`mssql_python/connection.py`,
[[1]](diffhunk://#diff-29bb94de45aae51c23a6426d40133c28e4161e68769e08d046059c7186264e90L273-R285);
`mssql_python/cursor.py`,
[[2]](diffhunk://#diff-deceea46ae01082ce8400e14fa02f4b7585afb7b5ed9885338b66494f5f38280L750-R737)
<!--
### PR Title Guide
> For feature requests
FEAT: (short-description)
> For non-feature requests like test case updates, config updates ,
dependency updates etc
CHORE: (short-description)
> For Fix requests
FIX: (short-description)
> For doc update requests
DOC: (short-description)
> For Formatting, indentation, or styling update
STYLE: (short-description)
> For Refactor, without any feature changes
REFACTOR: (short-description)
> For release related changes, without any feature changes
RELEASE: #<RELEASE_VERSION> (short-description)
-->
---------
Co-authored-by: Jahnvi Thakkar <61936179+jahnvi480@users.noreply.github.com>
0 commit comments